|
|
|
@ -35,6 +35,11 @@ public class EncryptionUtilsTests extends TestCase { |
|
|
|
assertEquals("3YIE8sIbaEoqGZZrHamFGQ==", encryptedString); |
|
|
|
assertEquals("3YIE8sIbaEoqGZZrHamFGQ==", encryptedString); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void testEncryptByteArrayUsingDESEde() { |
|
|
|
|
|
|
|
final byte[] encryptedArray = EncryptionUtils.encrypt(ENCRYPTION_KEY, EncryptionUtils.stringToByteArray(STRING_TO_ENCRYPT)); |
|
|
|
|
|
|
|
assertEquals("3YIE8sIbaEoqGZZrHamFGQ==", EncryptionUtils.byteArrayToString(encryptedArray)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testEncryptionKeyCanContainLetters() throws EncryptionException { |
|
|
|
public void testEncryptionKeyCanContainLetters() throws EncryptionException { |
|
|
|
final String encryptedString = EncryptionUtils.encrypt("ASDF asdf 1234 8983 jklasdf J2Jaf8", STRING_TO_ENCRYPT); |
|
|
|
final String encryptedString = EncryptionUtils.encrypt("ASDF asdf 1234 8983 jklasdf J2Jaf8", STRING_TO_ENCRYPT); |
|
|
|
assertEquals("v4+DQoClx6qm5tJwBcRrkw==", encryptedString); |
|
|
|
assertEquals("v4+DQoClx6qm5tJwBcRrkw==", encryptedString); |
|
|
|
@ -46,56 +51,62 @@ public class EncryptionUtilsTests extends TestCase { |
|
|
|
assertEquals(STRING_TO_ENCRYPT, decryptedString); |
|
|
|
assertEquals(STRING_TO_ENCRYPT, decryptedString); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testCantEncryptWithNullEncryptionKey() throws EncryptionException { |
|
|
|
public void testDecryptByteArrayUsingDESEde() { |
|
|
|
|
|
|
|
final byte[] encrypted = EncryptionUtils.stringToByteArray("3YIE8sIbaEoqGZZrHamFGQ=="); |
|
|
|
|
|
|
|
final byte[] decrypted = EncryptionUtils.decrypt(ENCRYPTION_KEY, encrypted); |
|
|
|
|
|
|
|
assertEquals(STRING_TO_ENCRYPT, EncryptionUtils.byteArrayToString(decrypted)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void testFailEncryptWithNullEncryptionKey() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
EncryptionUtils.encrypt(null, ""); |
|
|
|
EncryptionUtils.encrypt(null, STRING_TO_ENCRYPT); |
|
|
|
fail("Should have thrown IAE"); |
|
|
|
fail(); |
|
|
|
} catch (final IllegalArgumentException e) { |
|
|
|
} catch (IllegalArgumentException e) { |
|
|
|
assertTrue(true); |
|
|
|
assertTrue(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testCantEncryptWithEmptyEncryptionKey() throws EncryptionException { |
|
|
|
public void testFailEncryptWithEmptyEncryptionKey() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
EncryptionUtils.encrypt("", ""); |
|
|
|
EncryptionUtils.encrypt("", STRING_TO_ENCRYPT); |
|
|
|
fail("Should have thrown IAE"); |
|
|
|
fail(); |
|
|
|
} catch (final IllegalArgumentException e) { |
|
|
|
} catch (IllegalArgumentException e) { |
|
|
|
assertTrue(true); |
|
|
|
assertTrue(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testCantEncryptWithShortEncryptionKey() throws EncryptionException { |
|
|
|
public void teastFailEncryptWithShortEncryptionKey() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
EncryptionUtils.encrypt("01234567890123456789012", ""); |
|
|
|
EncryptionUtils.encrypt("01234567890123456789012", STRING_TO_ENCRYPT); |
|
|
|
fail("Should have thrown IAE"); |
|
|
|
fail(); |
|
|
|
} catch (final IllegalArgumentException e) { |
|
|
|
} catch (IllegalArgumentException e) { |
|
|
|
assertTrue(true); |
|
|
|
assertTrue(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testCantDecryptWithEmptyString() throws EncryptionException { |
|
|
|
public void testFailDecryptWithEmptyString() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
EncryptionUtils.decrypt(ENCRYPTION_KEY, ""); |
|
|
|
EncryptionUtils.decrypt(ENCRYPTION_KEY, ""); |
|
|
|
fail("Should have thrown IAE"); |
|
|
|
fail(); |
|
|
|
} catch (final IllegalArgumentException e) { |
|
|
|
} catch (IllegalArgumentException e) { |
|
|
|
assertTrue(true); |
|
|
|
assertTrue(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testCantEncryptWithEmptyString() throws EncryptionException { |
|
|
|
public void testFailEncryptWithEmptyString() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
EncryptionUtils.encrypt(ENCRYPTION_KEY, ""); |
|
|
|
EncryptionUtils.encrypt(ENCRYPTION_KEY, ""); |
|
|
|
fail("Should have thrown IAE"); |
|
|
|
fail(); |
|
|
|
} catch (final IllegalArgumentException e) { |
|
|
|
} catch (IllegalArgumentException e) { |
|
|
|
assertTrue(true); |
|
|
|
assertTrue(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testCantEncryptWithNullString() throws EncryptionException { |
|
|
|
public void testFailEncryptWithNullString() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
EncryptionUtils.encrypt(ENCRYPTION_KEY, null); |
|
|
|
EncryptionUtils.encrypt(ENCRYPTION_KEY, (String) null); |
|
|
|
fail("Should have thrown IAE"); |
|
|
|
fail(); |
|
|
|
} catch (final IllegalArgumentException e) { |
|
|
|
} catch (IllegalArgumentException e) { |
|
|
|
assertTrue(true); |
|
|
|
assertTrue(true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|