1 /*
2 * Title: S/MIME Project
3 * Description: S/MIME email sending capabilities
4 * @Author Vladimir Radisic
5 * @Version 2.0.1
6 */
7
8
9 package org.webdocwf.util.smime.cms;
10
11
12 import org.webdocwf.util.smime.exception.SMIMEException;
13 import org.webdocwf.util.smime.exception.ErrorStorage;
14 import java.security.MessageDigest;
15 import org.webdocwf.util.smime.der.DERSet;
16 import org.webdocwf.util.smime.der.DEROctetString;
17
18
19 /***
20 * MessageDigestAttribute is Signed Attribute and is used for creating CMS object
21 * for signed messages. It defines the type of digest used in CMS object in
22 * information about particular signing.
23 */
24 public class MessageDigestAttribute extends Attribute {
25
26 /***
27 * Performes construction and digesting of message in the same time
28 * @param message0 input massage for digest algorithm
29 * @param digestAlg0 object identifier name for digest algorithm (for
30 * example "SHA1")
31 * @exception SMIMEException caused by non SMIME exception which is
32 * NoSuchAlgorithmException if invalid digestAlg0 parameter is passed to the
33 * constructor. Also, exception could be thrown by super class constructor or
34 * by super class addContent method.
35 */
36 public MessageDigestAttribute(byte[] message0, String digestAlg0) throws SMIMEException {
37 super("ID_MESSAGEDIGEST", "NAME_STRING");
38 MessageDigest md = null;
39
40 try {
41 md = MessageDigest.getInstance(digestAlg0); // Performing digest function
42 } catch (Exception 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
49 digValue.addContent(dig.getDEREncoded());
50 super.addContent(digValue.getDEREncoded());
51 }
52 }
53
This page was automatically generated by Maven