parent
d0678c77ab
commit
1b22786001
|
@ -12,13 +12,8 @@ import java.nio.file.Paths;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.spec.InvalidKeySpecException;
|
import java.security.spec.InvalidKeySpecException;
|
||||||
|
|
||||||
//@SpringBootTest
|
|
||||||
class AESUtilUnitTest implements WithAssertions {
|
class AESUtilUnitTest implements WithAssertions {
|
||||||
|
|
||||||
@Test
|
|
||||||
void contextLoads() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenString_whenEncrypt_thenSuccess() throws NoSuchAlgorithmException {
|
void givenString_whenEncrypt_thenSuccess() throws NoSuchAlgorithmException {
|
||||||
// given
|
// given
|
||||||
|
@ -41,7 +36,8 @@ class AESUtilUnitTest implements WithAssertions {
|
||||||
SecretKey key = AESUtil.generateKey(128);
|
SecretKey key = AESUtil.generateKey(128);
|
||||||
String algorithm = "AES/CBC/PKCS5Padding";
|
String algorithm = "AES/CBC/PKCS5Padding";
|
||||||
IvParameterSpec ivParameterSpec = AESUtil.generateIv();
|
IvParameterSpec ivParameterSpec = AESUtil.generateIv();
|
||||||
File inputFile = Paths.get("src/test/resources/baeldung.txt").toFile();
|
File inputFile = Paths.get("src/test/resources/baeldung.txt")
|
||||||
|
.toFile();
|
||||||
File encryptedFile = new File("classpath:baeldung.encrypted");
|
File encryptedFile = new File("classpath:baeldung.encrypted");
|
||||||
File decryptedFile = new File("document.decrypted");
|
File decryptedFile = new File("document.decrypted");
|
||||||
|
|
||||||
|
@ -51,6 +47,8 @@ class AESUtilUnitTest implements WithAssertions {
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(inputFile).hasSameTextualContentAs(decryptedFile);
|
assertThat(inputFile).hasSameTextualContentAs(decryptedFile);
|
||||||
|
encryptedFile.delete();
|
||||||
|
decryptedFile.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -66,7 +64,7 @@ class AESUtilUnitTest implements WithAssertions {
|
||||||
Student object = (Student) AESUtil.decryptObject(algorithm, sealedObject, key, ivParameterSpec);
|
Student object = (Student) AESUtil.decryptObject(algorithm, sealedObject, key, ivParameterSpec);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(student).isEqualToComparingFieldByField(object);
|
assertThat(student).isEqualTo(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -86,4 +84,3 @@ class AESUtilUnitTest implements WithAssertions {
|
||||||
Assertions.assertEquals(plainText, decryptedCipherText);
|
Assertions.assertEquals(plainText, decryptedCipherText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue