Guest User

Untitled

a guest
Jun 22nd, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. $cipher = "rijndael-128";
  2. $mode = "cbc";
  3.  
  4. Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
  5.  
  6. SecretKey secret = new SecretKeySpec(key, "AES");
  7. Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
  8. cipher.init(Cipher.ENCRYPT_MODE, secret);
  9. AlgorithmParameters param = cipher.getParameters();
  10. /* In addition to ciphertext in "cos", recipient needs IV. */
  11. byte[] iv = param.getParameterSpec(IvParameterSpec.class).getIV();
  12. CipherOutputStream cos = new CipherOutputStream(output, cipher);
  13. byte[] buf = new byte[2048];
  14. while (true) {
  15. int n = input.read(buf, 0, buf.length);
  16. if (n < 0)
  17. break;
  18. cos.write(buf, 0, n);
  19. }
  20. cos.flush();
Add Comment
Please, Sign In to add comment