简体   繁体   中英

Is AES128 or AES256 on Android?

Greetings,

On Android, we can't specify AES128 or AES256. But is AES128, or AES256 actually run when using "AES/CBC/PKCS5Padding"?

I tried something like below

SecretKeyFactory sf = SecretKeyFactory.getInstance("PBEWITHSHAAND256BITAES-CBC-BC");
KeySpec ks = new PBEKeySpec(masterPassword.toCharArray(),k1,1320,256);
secKey = sf.generateSecret(ks);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secKey, generateIV(cipher));

The SecretKeyFactory created has a keySize of 256, and the keyLength specified in PBEKeySpec seems doesn't matter. No matter 256 or 128, or any other positive number, the secKey generated always has 256 keySize. Since we passed the secKey to initialize the cipher, so now, does the encryption will be run using AES128, or AES256?

Thanks!

This article should allow you to determine the strengths and ciphers you have available in the runtime image. I don't know if it will kick you out at this point but by specifying PBEKeySpec with a length of 256 I think you might have it.

On Android, we can't specify AES128 or AES256. But is AES128, or AES256 actually run when using "AES/CBC/PKCS5Padding"?

Am I wrong suggesting that none is actually determined at getInstance()? I suppose the length of the cipher's key will be determined only after call to init() where you set a key which is of certain length.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM