View Javadoc
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.der.DERSequencePr; 14 import java.security.cert.X509Certificate; 15 import org.webdocwf.util.smime.crypto.AsymmetricEncryption; 16 17 18 /*** 19 * KeyTransRecipientInfo class is DER encoded object represented in ASN.1 20 * notation according to RFC2630. It is used for representing information 21 * about particular recipient and for transport encrypted symmetric key. 22 * This class presents one way of transport symmetric key (they are 23 * two more ways). KeyTransRecipientInfo information in ASN.1 notation is 24 * represented as element named RecipientInfo (withouth s at the end!) which 25 * is inner element of RecipientInfos (for details look at RecipientInfo class).<BR> 26 * <BR> 27 * <DL> 28 * KeyTransRecipientInfo ::= SEQUENCE {<BR> 29 * <DD> version CMSVersion, -- always set to 0 or 2<BR> 30 * <DD> rid RecipientIdentifier,<BR> 31 * <DD> keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,<BR> 32 * <DD> encryptedKey EncryptedKey }<BR> 33 * </DL> 34 */ 35 public class KeyTransRecipientInfo extends DERSequencePr { 36 37 /*** 38 * Storage for symmetric key. 39 */ 40 private byte[] symmetricKey; 41 42 /*** 43 * Disable adding more than one recipient. 44 */ 45 private int enable = 0; 46 47 /*** 48 * Symmetric key is only important parameter, other can be null. 49 * @param symKey0 symmetric key represented as byte array 50 * @param parameter0 for future use 51 * @exception SMIMEException thrown by super class constructor. 52 */ 53 public KeyTransRecipientInfo(byte[] symKey0) throws SMIMEException { 54 symmetricKey = symKey0; // Before constructing this object symmetric key for encrypting of message content must already exist 55 } 56 57 /*** 58 * Adds recipient information. This method can be used just one time in one 59 * instance of this class. 60 * @param recip0 X509 certificate of the recipient 61 * @exception SMIMEException if recipient was already added. Also, exception 62 * could be thrown by super class addContent method. 63 */ 64 public void addRecipient(X509Certificate recip0) throws SMIMEException { 65 if (enable == 1) 66 throw new SMIMEException(this, 1022); 67 super.addContent(new CMSVersion(0).getDEREncoded()); // Setting CMS version to 1 68 super.addContent(new RecipientIdentifier(recip0).getDEREncoded()); // Adding issuer distinguish name + certificate serial number 69 super.addContent(new AlgorithmIdentifier("RSA", "NAME_STRING").getDEREncoded()); // Adding asymmetric algorythm object identifier 70 AsymmetricEncryption encrAsymmetric = new AsymmetricEncryption(); // Encrypting symmetric key 71 72 encrAsymmetric.encryption(recip0.getPublicKey(), symmetricKey); 73 EncryptedKey encKey = new EncryptedKey(encrAsymmetric.getEncryptValue()); 74 75 super.addContent(encKey.getDEREncoded()); // Adding encrypted symmetric key 76 enable = 1; 77 } 78 } 79

This page was automatically generated by Maven