More cipher tests

This commit is contained in:
vanitasvitae 2017-08-05 17:16:04 +02:00
parent 533cb97f7d
commit dcdee8d21a
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
1 changed files with 26 additions and 1 deletions

View File

@ -59,8 +59,18 @@ public class AesGcmNoPaddingTest extends SmackTestSuite {
assertEquals(256, aes256.getLength());
}
@Test(expected = NoSuchAlgorithmException.class)
public void invalidEncryptionCipher() throws NoSuchAlgorithmException, NoSuchPaddingException, NoSuchProviderException, InvalidKeyException, InvalidAlgorithmParameterException {
AesGcmNoPadding.createEncryptionKey("invalid");
}
@Test(expected = NoSuchAlgorithmException.class)
public void invalidDecryptionCipher() throws NoSuchAlgorithmException, NoSuchPaddingException, NoSuchProviderException, InvalidKeyException, InvalidAlgorithmParameterException {
AesGcmNoPadding.createDecryptionKey("invalid", null);
}
@Test
public void encryptionTest() throws NoSuchAlgorithmException, NoSuchPaddingException, NoSuchProviderException, InvalidKeyException, InvalidAlgorithmParameterException, BadPaddingException, IllegalBlockSizeException {
public void encryption128Test() throws NoSuchAlgorithmException, NoSuchPaddingException, NoSuchProviderException, InvalidKeyException, InvalidAlgorithmParameterException, BadPaddingException, IllegalBlockSizeException {
AesGcmNoPadding aes1 = AesGcmNoPadding.createEncryptionKey(Aes128GcmNoPadding.NAMESPACE);
AesGcmNoPadding aes2 = AesGcmNoPadding.createDecryptionKey(Aes128GcmNoPadding.NAMESPACE, aes1.getKeyAndIv());
@ -73,4 +83,19 @@ public class AesGcmNoPaddingTest extends SmackTestSuite {
byte[] dec = aes2.getCipher().doFinal(enc);
assertTrue(Arrays.equals(dec, data));
}
@Test
public void encryption256Test() throws NoSuchAlgorithmException, NoSuchPaddingException, NoSuchProviderException, InvalidKeyException, InvalidAlgorithmParameterException, BadPaddingException, IllegalBlockSizeException {
AesGcmNoPadding aes1 = AesGcmNoPadding.createEncryptionKey(Aes256GcmNoPadding.NAMESPACE);
AesGcmNoPadding aes2 = AesGcmNoPadding.createDecryptionKey(Aes256GcmNoPadding.NAMESPACE, aes1.getKeyAndIv());
byte[] data = new byte[4096];
new Random().nextBytes(data);
byte[] enc = aes1.getCipher().doFinal(data);
assertFalse(Arrays.equals(data, enc));
byte[] dec = aes2.getCipher().doFinal(enc);
assertTrue(Arrays.equals(dec, data));
}
}