Cryptix (encryption/decryption) question..a newbie new to encryption
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Kenneth_Chan
Posted On:   Tuesday, November 11, 2003 03:06 PM

I just doing a simple encryption/decryption using Cryptix and RSA in java. code // Given key are generated and provider setted up RSAPublicKey publicKey = (RSAPublicKey) pair.getPublic(); RSAPrivateKey privateKey = (RSAPrivateKey) pair.getPrivate(); Cipher c = Cipher.getInstance("RSA/ECB/PKCS#1"); c.init(Cipher.ENCRYPT_MODE, publicKey); byte[] ciphertext = c.doFinal(CLEARTEXT.getBytes ()); c.init(Cipher.DECRYPT_MODE, privateKey); byte[] decryptedText = c.doFinal(ciphertext);    More>>

I just doing a simple encryption/decryption using Cryptix and RSA in java.
code

			




// Given key are generated and provider setted up


RSAPublicKey publicKey = (RSAPublicKey)

pair.getPublic();


RSAPrivateKey privateKey = (RSAPrivateKey)

pair.getPrivate();


Cipher c = Cipher.getInstance("RSA/ECB/PKCS#1");


c.init(Cipher.ENCRYPT_MODE, publicKey);


byte[] ciphertext = c.doFinal(CLEARTEXT.getBytes

());


c.init(Cipher.DECRYPT_MODE, privateKey);


byte[] decryptedText = c.doFinal(ciphertext);




This works perfect and i can encrypt and decrypt text/string.
However I need to perform a double encryption via 2 different pairs of keys. If i insert another

			
byte[] ciphertexttwo = c.doFinal(ciphertext);




I will be throw to BadPaddingException error. I search around and think the answer is becos the padding needs 11 bytes more to execute...but i have no idea how to get around it. I tried to chop the byte[] shorter after encryption but it seems to make the thing worst. Any help /advise will be greatly appreciated. I even tried to revert the ciphertext back to string, and back to bytes etc..

   <<Less
About | Sitemap | Contact