Search in sources :

Example 16 with GCMParameterSpec

use of javax.crypto.spec.GCMParameterSpec in project jdk8u_jdk by JetBrains.

the class GCMParameterSpecTest method newGCMParameterSpecFail.

private static void newGCMParameterSpecFail(int tLen, byte[] src, int offset, int len) {
    try {
        new GCMParameterSpec(tLen, src, offset, len);
        new Exception("Didn't Fail as Expected").printStackTrace();
        failed++;
    } catch (IllegalArgumentException e) {
    // swallow
    }
}
Also used : GCMParameterSpec(javax.crypto.spec.GCMParameterSpec) AEADBadTagException(javax.crypto.AEADBadTagException)

Example 17 with GCMParameterSpec

use of javax.crypto.spec.GCMParameterSpec in project jdk8u_jdk by JetBrains.

the class GCMParameterSpecTest method newGCMParameterSpecPass.

private static void newGCMParameterSpecPass(int tLen, byte[] src, int offset, int len) {
    try {
        GCMParameterSpec gcmps = new GCMParameterSpec(tLen, src, offset, len);
        if (gcmps.getTLen() != tLen) {
            throw new Exception("tLen's not equal");
        }
        if (!Arrays.equals(gcmps.getIV(), Arrays.copyOfRange(src, offset, offset + len))) {
            System.out.println(offset + " " + len);
            System.out.println(Arrays.copyOfRange(src, offset, len)[0]);
            throw new Exception("IV's not equal");
        }
    } catch (Exception e) {
        e.printStackTrace();
        failed++;
    }
}
Also used : GCMParameterSpec(javax.crypto.spec.GCMParameterSpec) AEADBadTagException(javax.crypto.AEADBadTagException)

Aggregations

GCMParameterSpec (javax.crypto.spec.GCMParameterSpec)17 Cipher (javax.crypto.Cipher)8 SecretKey (javax.crypto.SecretKey)8 FileNotFoundException (java.io.FileNotFoundException)5 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 AEADBadTagException (javax.crypto.AEADBadTagException)3 BadPaddingException (javax.crypto.BadPaddingException)3 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)3 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)3 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 InvalidParameterSpecException (java.security.spec.InvalidParameterSpecException)2 NoSuchProviderException (java.security.NoSuchProviderException)1 Random (java.util.Random)1 KeyGenerator (javax.crypto.KeyGenerator)1 ShortBufferException (javax.crypto.ShortBufferException)1 SecretKeySpec (javax.crypto.spec.SecretKeySpec)1