Guest User

Untitled

a guest
Apr 24th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. Cipher cipher = Cipher.getInstance("AES");
  2. SecretKeySpec skey = new SecretKeySpec(DatatypeConverter.parseBase64Binary(Dispatcher.getK()), "AES");
  3. cipher.init(mod, skey);
  4. byte[] bytes = new byte[1024];
  5. int numBytes;
  6. if(mod == Cipher.ENCRYPT_MODE) {
  7. CipherOutputStream cos = new CipherOutputStream(outputFile, cipher);
  8. while ((numBytes = inputFile.read(bytes)) != -1){
  9. cos.write(bytes, 0, numBytes);
  10. }
  11. cos.flush();
  12. cos.close();
  13. inputFile.close();
  14. }
  15. if (mod == Cipher.DECRYPT_MODE){
  16. CipherInputStream cis = new CipherInputStream(inputFile, cipher);
  17. while ((numBytes = cis.read(bytes)) != -1){
  18. outputFile.write(bytes, 0, numBytes);
  19. }
  20. outputFile.flush();
  21. outputFile.close();
  22. cis.close();
  23. }
Add Comment
Please, Sign In to add comment