Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encrypt with PHP, decrypt with Java does not work #1

Open
sthomasy opened this issue Feb 19, 2014 · 4 comments
Open

encrypt with PHP, decrypt with Java does not work #1

sthomasy opened this issue Feb 19, 2014 · 4 comments

Comments

@sthomasy
Copy link

Thanks for the clean code. However, when I tries to run it, it has a problem. It works beautifully when encrypt/decrypt with the same language (encrypt with php, then decrypt with php, or encrypt with Java, then decrypt with Java). But when I tried to encrypt a string, then try to decrypt with Java, it does not work. For example, encrypt the string "123456789" in php gives "xclAYNWIbzt6bZ1ewhdEjQ==". Encrypt the same string "123456789" in Java gives "udpnHfeBRTsrcKwzAs5law==". when trying to decrypt the php encrypted string, I got an Java BadPaddingException error:

javax.crypto.BadPaddingException: Given final block not properly padded
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:811)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676)
at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:313)
at javax.crypto.Cipher.doFinal(Cipher.java:2087)
at Main.decryptStr(Main.java:544)
at Main.main(Main.java:135)

@Nik144
Copy link

Nik144 commented Sep 1, 2015

hey please give me the solution. i am getting same problem.

@kdkaushik
Copy link

I want to encrypt in java and decrypt in php...... please help

@joemakev
Copy link

For those who are have error with java decryption, find the line with:
output = cipher.doFinal(Base64.decodeBase64(input));

Then replace it with:
output = cipher.doFinal(Base64.decodeBase64(input.getBytes()));

@lekeCoder
Copy link

I keep getting the error: key length not 128/192/256 bits.

I generated my keys using KeyGenerator with AES.
What could be the problem? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants