Exemplo n.º 1
0
  MacData(String algName, byte[] digest, byte[] salt, int iterations)
      throws NoSuchAlgorithmException {
    if (algName == null)
      throw new NullPointerException("the algName parameter " + "must be non-null");

    AlgorithmId algid = AlgorithmId.get(algName);
    this.digestAlgorithmName = algid.getName();
    this.digestAlgorithmParams = algid.getParameters();

    if (digest == null) {
      throw new NullPointerException("the digest " + "parameter must be non-null");
    } else if (digest.length == 0) {
      throw new IllegalArgumentException("the digest " + "parameter must not be empty");
    } else {
      this.digest = digest.clone();
    }

    this.macSalt = salt;
    this.iterations = iterations;

    // delay the generation of ASN.1 encoding until
    // getEncoded() is called
    this.encoded = null;
  }
Exemplo n.º 2
0
  /** Parses a PKCS#12 MAC data. */
  MacData(DerInputStream derin) throws IOException, ParsingException {
    DerValue[] macData = derin.getSequence(2);

    // Parse the digest info
    DerInputStream digestIn = new DerInputStream(macData[0].toByteArray());
    DerValue[] digestInfo = digestIn.getSequence(2);

    // Parse the DigestAlgorithmIdentifier.
    AlgorithmId digestAlgorithmId = AlgorithmId.parse(digestInfo[0]);
    this.digestAlgorithmName = digestAlgorithmId.getName();
    this.digestAlgorithmParams = digestAlgorithmId.getParameters();
    // Get the digest.
    this.digest = digestInfo[1].getOctetString();

    // Get the salt.
    this.macSalt = macData[1].getOctetString();

    // Iterations is optional. The default value is 1.
    if (macData.length > 2) {
      this.iterations = macData[2].getInteger();
    } else {
      this.iterations = 1;
    }
  }