SEC-3002: Add new option for AES encryption with GCM
The Galois Counter Mode (GCM) is held to be superior than the current default CBC. This change adds an extra parameter to the constructor of AesBytesEncryptor and a new convenience method in Encryptors.
This commit is contained in:
@@ -9,6 +9,17 @@ import org.junit.Test;
|
||||
|
||||
public class EncryptorsTests {
|
||||
|
||||
@Test
|
||||
public void stronger() throws Exception {
|
||||
BytesEncryptor encryptor = Encryptors.stronger("password", "5c0744940b5c369b");
|
||||
byte[] result = encryptor.encrypt("text".getBytes("UTF-8"));
|
||||
assertNotNull(result);
|
||||
assertFalse(new String(result).equals("text"));
|
||||
assertEquals("text", new String(encryptor.decrypt(result)));
|
||||
assertFalse(new String(result).equals(new String(encryptor.encrypt("text"
|
||||
.getBytes()))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void standard() throws Exception {
|
||||
BytesEncryptor encryptor = Encryptors.standard("password", "5c0744940b5c369b");
|
||||
@@ -20,6 +31,16 @@ public class EncryptorsTests {
|
||||
.getBytes()))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preferred() {
|
||||
TextEncryptor encryptor = Encryptors.delux("password", "5c0744940b5c369b");
|
||||
String result = encryptor.encrypt("text");
|
||||
assertNotNull(result);
|
||||
assertFalse(result.equals("text"));
|
||||
assertEquals("text", encryptor.decrypt(result));
|
||||
assertFalse(result.equals(encryptor.encrypt("text")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void text() {
|
||||
TextEncryptor encryptor = Encryptors.text("password", "5c0744940b5c369b");
|
||||
|
||||
Reference in New Issue
Block a user