【发布时间】:2015-01-04 11:23:27
【问题描述】:
我正在创建一个使用安卓手机更新固件的产品。 android 应用程序会自动下载固件的加密版本,对其进行解密,然后将其发送到设备引导加载程序。为了生成相同的密钥,我在代码中指定了密码和盐。我担心apk会被反编译,有人会解密我们的固件。
有没有更好的方法来解密/加密文件或保护代码?
代码:
private byte[] DecryptFile(byte[] encryptedFileBuffer) {
final int iterationCount = 10;
byte[] dataDecrypted = null;
SecretKey secKey = null;
try {
byte[] salt = "salt1234".getBytes();
String accessThingy = "Password";
KeySpec keySpec = new PBEKeySpec(accessThingy.toCharArray(), salt, iterationCount);
secKey = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCount);
Cipher desCipher;
// Create the cipher
desCipher = Cipher.getInstance(secKey.getAlgorithm());
desCipher.init(Cipher.DECRYPT_MODE, secKey,paramSpec);
dataDecrypted = desCipher.doFinal(encrptedFileBuffer);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
return dataDecrypted;
}
【问题讨论】:
标签: android encryption cryptography decompiling copy-protection