· 6 years ago · Jan 31, 2019, 10:52 PM
1public byte[] encrypt(byte[] plainTextByte, SecretKey secretKey,String algorithm)//zavrsiti ovu funkciju koja enkriptuje fajl
2 throws Exception {
3 Cipher cipher = Cipher.getInstance(algorithm);
4 cipher.init(Cipher.ENCRYPT_MODE, secretKey);
5 byte[] encryptedBytes = cipher.doFinal(plainTextByte);
6
7 return encryptedBytes;
8 }
9
10 public byte[] decrypt(byte[] encryptedBytes, SecretKey secretKey,String algorithm)
11 throws Exception {
12 Cipher cipher = Cipher.getInstance(algorithm);
13 cipher.init(Cipher.DECRYPT_MODE, secretKey);
14 byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
15 return decryptedBytes;
16 }