· 7 years ago · Aug 06, 2018, 07:50 PM
1PDF encryption/Decryption in android?
2FileInputStream fis = new FileInputStream(new File("D:/Shashank/Test123.txt"));
3 File outfile = new File("D:/Shashank/encTest1234.txt");
4 int read;
5 if(!outfile.exists())
6 outfile.createNewFile();
7 File decfile = new File("D:/Shashank/dec123.txt");
8 if(!decfile.exists())
9 decfile.createNewFile();
10 FileOutputStream fos = new FileOutputStream(outfile);
11 FileInputStream encfis = new FileInputStream(outfile);
12 FileOutputStream decfos = new FileOutputStream(decfile);
13 Cipher encipher = Cipher.getInstance("AES");
14 Cipher decipher = Cipher.getInstance("AES");
15 KeyGenerator kgen = KeyGenerator.getInstance("AES");
16 SecretKey skey = kgen.generateKey();
17 encipher.init(Cipher.ENCRYPT_MODE, skey);
18 CipherInputStream cis = new CipherInputStream(fis, encipher);
19 decipher.init(Cipher.DECRYPT_MODE, skey);
20 CipherOutputStream cos = new CipherOutputStream(decfos,decipher);
21 while((read = cis.read())!=-1)
22 {
23 fos.write((char)read);
24 fos.flush();
25 }
26 fos.close();
27 while((read=encfis.read())!=-1)
28 {
29 cos.write(read);
30 cos.flush();
31 }
32 cos.close();