1 7 8 9 package org.enhydra.oyster.crypto; 10 11 import java.security.Key ; 12 import javax.crypto.Cipher; 13 import org.enhydra.oyster.exception.SMIMEException; 14 import org.enhydra.oyster.exception.ErrorStorage; 15 16 17 26 public class AsymmetricEncryption { 27 28 31 private byte[] encryptContent = null; 32 33 36 private byte[] decryptContent = null; 37 38 39 42 public AsymmetricEncryption () { 43 } 44 45 54 public void encrypt (Key key0, byte[] forEncrypt0) throws SMIMEException{ 55 try { 56 Cipher c = Cipher.getInstance("RSA/ECB/PKCS1Padding", "BC"); 57 c.init(Cipher.ENCRYPT_MODE, key0); 58 encryptContent = c.doFinal(forEncrypt0); 59 } 60 catch(Exception e) { 61 throw SMIMEException.getInstance(this, e, "encryption" ); 62 } 63 } 64 65 69 public byte[] getEncryptedValue () { 70 return encryptContent; 71 } 72 73 81 public void decrypt (Key key0, byte[] forDecrypt0) throws SMIMEException{ 82 try { 83 Cipher c = Cipher.getInstance("RSA/ECB/PKCS1Padding", "BC"); 84 c.init(Cipher.DECRYPT_MODE, key0); 85 decryptContent = c.doFinal(forDecrypt0); 86 } 87 catch(Exception e) { 88 throw SMIMEException.getInstance(this, e, "decryption" ); 89 } 90 } 91 92 97 public byte[] getDecryptedValue () { 98 return decryptContent; 99 } 100 101 105 void reset () { 106 encryptContent = null; 107 decryptContent = null; 108 } 109 } 110 | Popular Tags |