mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 20:42:06 +01:00
More cipher tests
This commit is contained in:
parent
533cb97f7d
commit
dcdee8d21a
1 changed files with 26 additions and 1 deletions
|
@ -59,8 +59,18 @@ public class AesGcmNoPaddingTest extends SmackTestSuite {
|
||||||
assertEquals(256, aes256.getLength());
|
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
|
@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 aes1 = AesGcmNoPadding.createEncryptionKey(Aes128GcmNoPadding.NAMESPACE);
|
||||||
AesGcmNoPadding aes2 = AesGcmNoPadding.createDecryptionKey(Aes128GcmNoPadding.NAMESPACE, aes1.getKeyAndIv());
|
AesGcmNoPadding aes2 = AesGcmNoPadding.createDecryptionKey(Aes128GcmNoPadding.NAMESPACE, aes1.getKeyAndIv());
|
||||||
|
|
||||||
|
@ -73,4 +83,19 @@ public class AesGcmNoPaddingTest extends SmackTestSuite {
|
||||||
byte[] dec = aes2.getCipher().doFinal(enc);
|
byte[] dec = aes2.getCipher().doFinal(enc);
|
||||||
assertTrue(Arrays.equals(dec, data));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue