• No replies
6902 Posts

Pinned topic Issue with getOutputSize method of Cipher class

‏2013-04-05T13:15:49Z |
Hi, I am facing an issue with return value from method getOutputSize of Cipher class.

byte[] encryptedBytes = Base64.decodeBase64(encryptedStr); Cipher rsaCipher = Cipher.getInstance(
"RSA"); rsaCipher.init(Cipher.DECRYPT_MODE, getPrivateKey()); *

int bufsiz = rsaCipher.getOutputSize(KEYSIZE);* 

byte[] aesBytes = Arrays.copyOfRange(encryptedBytes, 0, bufsiz); 

byte[] passwdBytes = Arrays.copyOfRange(encryptedBytes, bufsiz, encryptedBytes.length); SecretKey aesKey = getAESKey(rsaCipher.doFinal(aesBytes));

I am getting exception in last line (doFinal method) -
javax.crypto.BadPaddingException: Not PKCS#1 block type 2 or Zero padding

This because of the value of bufsiz is 257. If I change this to 256 in debug mode, it execute successfully.
This code is working fine on WIndows, Solaris. Is this known issue in AIX ?
Can someone help ?