Encrypt and Decrypt by AES algorithm in both python and android

后端 未结 1 1416
抹茶落季
抹茶落季 2021-02-04 17:07

I have python and android code for AES encryption. When I encrypt a text in android, it decrypt on python successfully but it can’t decrypt in android side. Do anyone have an

相关标签:
1条回答
  • 2021-02-04 17:52

    You're encoding the output after decryption.

    public String decrypt_string(final String plain) throws ...
    {
        byte[] encryptedBytes = decrypt(Base64.decode(plain, 0));
        return Base64.encodeToString( encryptedBytes, Base64.DEFAULT);
        //     ^--------------------| this 
    }
    

    If you only encrypt printable data then you can safely remove the Base64.encodeToString call from the above code. To return the correct type, you can do

    return new String(encryptedBytes);
    
    0 讨论(0)
提交回复
热议问题