【发布时间】:2018-10-03 21:01:18
【问题描述】:
我在 2 年前使用此代码段来加密我的图像数据。当时我的目标 SDK 是 22。但是当我尝试更新我的 SDK 时,我面临我无法解密它。我发现 Android 弃用了这种加密方法。有什么办法可以解决这个问题,以便我可以解密我的图像。 提前致谢。
public byte[] EncryptByte(byte[] rawInputByte){
byte[] fileBytes = null;
try {
byte[] yourKey = generateKey("password");
fileBytes = encodeFile(yourKey, rawInputByte);
} catch (Exception e) {
e.printStackTrace();
}
return fileBytes;
}
public byte[] generateKey(String password) throws Exception
{
byte[] keyStart = password.getBytes("UTF-8");
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto");
sr.setSeed(keyStart);
kgen.init(128, sr);
SecretKey skey = kgen.generateKey();
return skey.getEncoded();
}
【问题讨论】:
标签: java android encryption cryptography