Error encode/decode Base64 between Java and Android

后端 未结 1 1782
没有蜡笔的小新
没有蜡笔的小新 2021-02-10 21:15

I have a problem when I encode/decode Base64 between Java and Android.

Here is my case:

I write code to encrypt/decrypt using ECC on Java, my code work very well

1条回答
  •  南笙
    南笙 (楼主)
    2021-02-10 21:54

    This seems to be a simple mistake. You replaced

    String abc = Base64.getDecoder().decode(encrypt);
    

    with

    byte[] encodeBytes = null;
    encodeBytes = Base64.encode(my_encrypted_string.getBytes(),Base64.DEFAULT);
    

    if I read this correctly. Try to replace that with decode instead.

    As the ciphertext is Base64 encoded twice instead of decoded before attempting to decrypt it, decryption fails with the error you showed us.

    0 讨论(0)
提交回复
热议问题