如何对sd卡上的应用程序文件进行加密和解密?这样我就可以保护 SD 卡上的文件,并且其他人无法在不解密这些文件的情况下访问该应用程序之外的内容?
有没有人可以给我任何好的示例源来在 Android 应用程序上实现加密?
我编写了这个程序,它将使用 AES 加密文件并解密同一文件。这肯定会对你有帮助。
FileInputStream fis = new FileInputStream(new File("D:/Shashank/Test123.txt"));
File outfile = new File("D:/Shashank/encTest1234.txt");
int read;
if(!outfile.exists())
outfile.createNewFile();
File decfile = new File("D:/Shashank/dec123.txt");
if(!decfile.exists())
decfile.createNewFile();
FileOutputStream fos = new FileOutputStream(outfile);
FileInputStream encfis = new FileInputStream(outfile);
FileOutputStream decfos = new FileOutputStream(decfile);
Cipher encipher = Cipher.getInstance("AES");
Cipher decipher = Cipher.getInstance("AES");
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecretKey skey = kgen.generateKey();
encipher.init(Cipher.ENCRYPT_MODE, skey);
CipherInputStream cis = new CipherInputStream(fis, encipher);
decipher.init(Cipher.DECRYPT_MODE, skey);
CipherOutputStream cos = new CipherOutputStream(decfos,decipher);
while((read = cis.read())!=-1)
{
fos.write((char)read);
fos.flush();
}
fos.close();
while((read=encfis.read())!=-1)
{
cos.write(read);
cos.flush();
}
cos.close();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)