On Wed, November 21, 2007 2:39 pm, Lidia Fernández wrote: > I have to encrypt a file in c with openssl and then i have to decrypt in > Java. > > In Java i use to decrypt the algorithm > > Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); > > With OpenSSL i use > > openssl enc -a -des-ecb -in file -out file.enc -pass pass:abcdefgh > > but i have an error message in Java that say > > javax.crypto.BadPaddingException: Given final block not properly padded > > > What padding does OpenSSL use??? How can i specify the padding??
Having just recently been grappling with this, you need to make sure, in your OpenSSL code, that the EVP_EncryptFinal_ex() function is being executed correctly on the last block of data. Left to the defaults, EVP_EncryptFinal_ex worries about the padding, you do not need to do anything. One problem that I did encounter was issues with the length of the encrypted block. In my code, I was encrypting the block, and then base64 encoding the result. I then un-base64-encoded the result, and then applied the decryption to reverse the process. The problem was in my case that the length I was using to decrypt the code was the length returned by the base64 decoder, which was adding 1 to the real length to be a terminating 0 character. OpenSSL then complained that it could not decrypt the final block. In other words, double check your lengths and make sure they are correct all the way through. Regards, Graham -- ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]