Android文件加密是指使用密码或其他安全技术,将Android文件的内容变得不可读,以保护文件的安全性。是一个使用AES-128位加密的Android文件加密的示例代码:
Android文件加密是指使用密码或其他安全技术,将Android文件的内容变得不可读,以保护文件的安全性。
是一个使用AES-128位加密的Android文件加密的示例代码:
// 定义加密算法
String algorithm = "AES/CBC/PKCS5Padding";
// 获取加密密钥
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(128);
SecretKey secretKey = keyGenerator.generateKey();
// 创建加密对象
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
// 加密文件
FileInputStream inputStream = new FileInputStream(file);
byte[] inputBytes = new byte[(int) file.length()];
inputStream.read(inputBytes);
byte[] outputBytes = cipher.doFinal(inputBytes);
// 保存加密后的文件
FileOutputStream outputStream = new FileOutputStream(encryptedFile);
outputStream.write(outputBytes);
inputStream.close();
outputStream.close();
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(48条)