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:
Dave Syer
2015-06-09 15:21:28 +01:00
committed by Rob Winch
parent ca0ffb8b5d
commit a48cc18858
4 changed files with 125 additions and 20 deletions

View File

@@ -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");