1 7 8 9 package org.enhydra.oyster.cms; 10 11 import org.enhydra.oyster.exception.SMIMEException; 12 import org.enhydra.oyster.der.DERSetPr; 13 import org.enhydra.oyster.der.DERSequence; 14 import java.security.cert.X509Certificate ; 15 import java.security.PrivateKey ; 16 17 18 37 public class SignerInfos extends DERSetPr { 38 39 42 private int countIndicator = 0; 43 44 48 public SignerInfos () throws SMIMEException 49 { 50 } 51 52 65 public void addSigner (byte[] message0, X509Certificate cert0, PrivateKey privKey0, SignedAttributes sAttr0, String signedAlg0) throws SMIMEException { 66 String digAlg = null; 67 String sigAlg = null; 68 if (signedAlg0.equalsIgnoreCase("SHA1_WITH_RSA")) { 69 digAlg = "SHA1"; 70 sigAlg = "RSA"; 71 } 72 else if (signedAlg0.equalsIgnoreCase("SHA1_WITH_DSA")) { 73 digAlg = "SHA1"; 74 sigAlg = "DSA"; 75 } 76 else if (signedAlg0.equalsIgnoreCase("MD2_WITH_RSA")) { 77 digAlg = "MD2"; 78 sigAlg = "RSA"; 79 } 80 else if (signedAlg0.equalsIgnoreCase("MD5_WITH_RSA")) { 81 digAlg = "MD5"; 82 sigAlg = "RSA"; 83 } 84 DERSequence signerInfo = new DERSequence(); 85 signerInfo.addContent(new CMSVersion(1).getDEREncoded()); if (cert0 == null) 87 throw new SMIMEException(this, 1026); 88 SignerIdentifier signIdent = new SignerIdentifier(cert0); 89 signerInfo.addContent(signIdent.getSignIdentifier()); 90 AlgorithmIdentifier digestAlg = new AlgorithmIdentifier(digAlg, "NAME_STRING"); 91 digestAlg.addNullToAlgorithmId(); 92 signerInfo.addContent(digestAlg.getDEREncoded()); if (sAttr0 != null) 94 signerInfo.addContent(sAttr0.getSignedAttribute()); AlgorithmIdentifier signedAlg = new AlgorithmIdentifier(sigAlg, "NAME_STRING"); 96 signedAlg.addNullToAlgorithmId(); 97 signerInfo.addContent(signedAlg.getDEREncoded()); if (privKey0 == null) 99 throw new SMIMEException(this, 1027); 100 SignatureValue sigVal = null; 101 if (sAttr0 == null) sigVal = new SignatureValue(message0, privKey0, signedAlg0); 103 else { 104 byte[] tempByte = sAttr0.getSignedAttribute(); 105 tempByte[0] = 49; sigVal = new SignatureValue(tempByte, privKey0, signedAlg0); 107 } 108 signerInfo.addContent(sigVal.getDEREncoded()); super.addContent(signerInfo.getDEREncoded()); countIndicator++; 111 } 112 } 113 114 115 116 | Popular Tags |