1 7 8 9 package org.enhydra.oyster.crypto; 10 11 import org.enhydra.oyster.exception.SMIMEException; 12 import org.enhydra.oyster.exception.ErrorStorage; 13 import java.security.PrivateKey ; 14 import java.security.Signature ; 15 import org.bouncycastle.jce.provider.JDKDigestSignature; 16 17 18 23 public class SigningProcessor { 24 25 37 public static byte[] getSignature (byte[] forSigning0, PrivateKey key0, String signAlg0) throws SMIMEException { 38 byte[] sVal = null; 39 try { 40 if (signAlg0.equalsIgnoreCase("SHA1_WITH_RSA")) { 41 JDKDigestSignature.SHA1WithRSAEncryption jd = new JDKDigestSignature.SHA1WithRSAEncryption(); 42 jd.initSign(key0); 43 jd.update(forSigning0); 44 sVal = jd.sign(); 45 } 46 else if (signAlg0.equalsIgnoreCase("SHA1_WITH_DSA")) { 47 Signature sig = Signature.getInstance("SHA1withDSA", "SUN"); 48 sig.initSign(key0); 49 sig.update(forSigning0); 50 sVal = sig.sign(); 51 } 52 else if (signAlg0.equalsIgnoreCase("MD2_WITH_RSA")) { 53 JDKDigestSignature.MD2WithRSAEncryption jd = new JDKDigestSignature.MD2WithRSAEncryption(); 54 jd.initSign(key0); 55 jd.update(forSigning0); 56 sVal = jd.sign(); 57 } 58 else if (signAlg0.equalsIgnoreCase("MD5_WITH_RSA")) { 59 JDKDigestSignature.MD5WithRSAEncryption jd = new JDKDigestSignature.MD5WithRSAEncryption(); 60 jd.initSign(key0); 61 jd.update(forSigning0); 62 sVal = jd.sign(); 63 } 64 } 65 catch(Exception e) { 66 throw SMIMEException.getInstance("org.enhydra.oyster.crypto.SigningProcessor", 67 e, "getSignature" ); 68 } 69 return sVal; 70 } 71 } 72 73 74 75 | Popular Tags |