AES gingerbread

This is my code for AES.

In Gingerbread, I get the following error after encrypting data on 2.2, then trying to decrypt in version 2.3:

 Caused by: javax.crypto.BadPaddingException: pad block corrupted
        at org.bouncycastle.jce.provider.JCEBlockCipher.engineDoFinal(JCEBlockCipher.java:715)
        at javax.crypto.Cipher.doFinal(Cipher.java:1090)
        at com.citc.wallet.util.security.SimpleCrypto.decrypt(SimpleCrypto.java:63)
        ... 21 more

I found several posts that SecureRandomproduce different results on different systems:

BouncyCastle AES error when upgrading to 1.45

How to avoid this problem on 2.3?
Can I somehow force 2.3 to use the same SecureRandom class?
Do I need to use some portable encryption method, and if so, then what?

+3
source share
1 answer

The answer is that you really should not do what you do. Here is the culprit:

sr.setSeed(seed);
kgen.init(128, sr); // 192 and 256 bits may not be available
SecretKey skey = kgen.generateKey();

, . android docs

"Seeding SecureRandom "

, SecureRandom, .

, , , "" , , , .

128 192 256- , 192 256 . 0 , , , - , .

, , , , , Android. "" .

+4

Source: https://habr.com/ru/post/1782218/


All Articles