· 7 years ago · Nov 17, 2018, 04:32 PM
1//ENCRYPTED_CONTENT zawiera dane które znamy że są poprawną wersją zaszyfrowaną tekstu "przykładowy"
2static byte[] ENCRYPTED_CONTENT = Base64.getDecoder().decode("np base64 string");
3static String t = "przykładowy";
4static byte[] keyArr = {120, -72, -74, -101, 76, 11, 79, -46, -73, -16, 66, 115, 98, 58, 0, -35};
5
6//należy przekazać do szyfrowania
7static SecretKey KEY = new SecretKeySpec(keyArr, 0, keyArr.length, "DESede");
8
9@Test
10public void testEncryptFile() throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IOException {
11 File file = new File("path");
12 Files.write(file.toPath(), t.getBytes());
13 encryptFile(KEY, file);
14 byte[] encrypted = Files.readAllBytes(Paths.get("zaszyfrowany.cfr"));
15 assertArrayEquals(ENCRYPTED_CONTENT, encrypted);
16}