KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > oyster > cms > MessageDigestAttribute


1 /*
2  * Title: Oyster Project
3  * Description: S/MIME email sending capabilities
4  * @Author Vladimir Radisic
5  * @Version 2.1.5
6  */

7
8
9 package org.enhydra.oyster.cms;
10
11 import org.enhydra.oyster.exception.SMIMEException;
12 import org.enhydra.oyster.exception.ErrorStorage;
13 import java.security.MessageDigest JavaDoc;
14 import org.enhydra.oyster.der.DERSet;
15 import org.enhydra.oyster.der.DEROctetString;
16
17
18 /**
19  * MessageDigestAttribute is Signed Attribute and is used for creating CMS object
20  * for signed messages. It defines the type of digest used in CMS object in
21  * information about particular signing.
22  */

23 public class MessageDigestAttribute extends Attribute {
24
25 /**
26  * Performes construction and digesting of message in the same time
27  * @param message0 input massage for digest algorithm
28  * @param digestAlg0 object identifier name for digest algorithm (for
29  * example "SHA1")
30  * @exception SMIMEException caused by non SMIME exception which is
31  * NoSuchAlgorithmException if invalid digestAlg0 parameter is passed to the
32  * constructor. Also, exception could be thrown by super class constructor or
33  * by super class addContent method.
34  */

35   public MessageDigestAttribute (byte[] message0, String JavaDoc digestAlg0) throws SMIMEException
36   {
37     super("ID_MESSAGEDIGEST", "NAME_STRING");
38     MessageDigest JavaDoc md = null;
39     try {
40       md = MessageDigest.getInstance(digestAlg0); // Performing digest function
41
}
42     catch(Exception JavaDoc e) {
43       throw SMIMEException.getInstance(this, e, "constructor" );
44     }
45     md.update(message0);
46     DEROctetString dig = new DEROctetString(md.digest());
47     DERSet digValue = new DERSet();
48     digValue.addContent(dig.getDEREncoded());
49     super.addContent(digValue.getDEREncoded());
50   }
51 }
52
53
54
55
Popular Tags