Android 8.0: IllegalBlocksizeException when using RSA/ECB/OAEPWithSHA-512AndMGF1Padding

前端 未结 1 1964
失恋的感觉
失恋的感觉 2021-02-02 01:39

I usually find answers for most of our issues here but this time I need to ask :-).

We have encountered a problem with RSA encryption / decryption in one of our Apps run

相关标签:
1条回答
  • 2021-02-02 02:31

    A possible solution is described here in the comment #15 from Sep 8, 2017 07:08PM:

    https://issuetracker.google.com/issues/36708951#comment15

    I changed the Cipher-Initialisation from

    Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
    cipher.init(Cipher.DECRYPT_MODE, this.getPrivateKey(context));
    

    to

    OAEPParameterSpec sp = new OAEPParameterSpec("SHA-256", "MGF1", new MGF1ParameterSpec("SHA-1"), PSource.PSpecified.DEFAULT);
    Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
    cipher.init(Cipher.DECRYPT_MODE, this.getPrivateKey(context), sp);
    

    I tested this on Android 6 up to Android 8 (emulator) and the issue seems to be gone. You should also change the Cipher.ENCRYPT_MODE-Implementation.

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