Skip to content

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

@sthomasy

Description

@sthomasy

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions