相关疑难解决方法(0)

Android:使用带有iv和密钥的AES 256位加密来加密字符串

SecureRandom random = new SecureRandom(); // quite heavy, look into a lighter method.

String stringToEncrypt = "mypassword";
byte[] realiv = new byte[16];
random.nextBytes(realiv);
Cipher ecipher = Cipher.getInstance("AES");

SecureRandom random = new SecureRandom(); // quite heavy, look into a lighter method.

byte[] realiv = new byte[16];
random.nextBytes(realiv);       

byte[] secret = "somelongsecretkey".getBytes();
SecretKeySpec secretKey = new SecretKeySpec(secret, "AES");
ecipher.init(Cipher.ENCRYPT_MODE, secretKey, random);
byte[] encryptedData = ecipher.doFinal();
Run Code Online (Sandbox Code Playgroud)

init()唯一需要3个参数.我需要一种方法来做类似的事情:

ecipher.init(Cipher.ENCRYPT_MODE, stringToEncrypt, secretKey, random);
Run Code Online (Sandbox Code Playgroud)

java encryption android aes

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

aes ×1

android ×1

encryption ×1

java ×1