Example #1
0
  /**
   * Returns the ASN.1 encoding of this object.
   *
   * @return the ASN.1 encoding.
   * @exception IOException if error occurs when constructing its ASN.1 encoding.
   */
  public byte[] getEncoded() throws NoSuchAlgorithmException, IOException {
    if (this.encoded != null) return this.encoded.clone();

    DerOutputStream out = new DerOutputStream();
    DerOutputStream tmp = new DerOutputStream();

    DerOutputStream tmp2 = new DerOutputStream();
    // encode encryption algorithm
    AlgorithmId algid = AlgorithmId.get(digestAlgorithmName);
    algid.encode(tmp2);

    // encode digest data
    tmp2.putOctetString(digest);

    tmp.write(DerValue.tag_Sequence, tmp2);

    // encode salt
    tmp.putOctetString(macSalt);

    // encode iterations
    tmp.putInteger(iterations);

    // wrap everything into a SEQUENCE
    out.write(DerValue.tag_Sequence, tmp);
    this.encoded = out.toByteArray();

    return this.encoded.clone();
  }
Example #2
0
 private static void writeSignatureBlock(
     Signature signature, X509Certificate publicKey, OutputStream out)
     throws IOException, GeneralSecurityException {
   SignerInfo signerInfo =
       new SignerInfo(
           new X500Name(publicKey.getIssuerX500Principal().getName()),
           publicKey.getSerialNumber(),
           AlgorithmId.get("SHA1"),
           AlgorithmId.get("RSA"),
           signature.sign());
   PKCS7 pkcs7 =
       new PKCS7(
           new AlgorithmId[] {AlgorithmId.get("SHA1")},
           new ContentInfo(ContentInfo.DATA_OID, null),
           new X509Certificate[] {publicKey},
           new SignerInfo[] {signerInfo});
   pkcs7.encodeSignedData(out);
 }
Example #3
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;
  }