Examples of GCMBlockCipher


Examples of org.bouncycastle.crypto.modes.GCMBlockCipher

    super(id, algorithm, keySize, ivSize, needsUnlimitedStrength);
  }
   
  @Override
  public OutputStream newCipherOutputStream(OutputStream underlyingOutputStream, byte[] secretKey, byte[] iv) throws CipherException {
    AEADBlockCipher cipher = new GCMBlockCipher(new TwofishEngine());
    cipher.init(true, new AEADParameters(new KeyParameter(secretKey), MAC_SIZE, iv));
   
    return new org.bouncycastle.crypto.io.CipherOutputStream(underlyingOutputStream, cipher);
  }
View Full Code Here

Examples of org.bouncycastle.crypto.modes.GCMBlockCipher

    return new org.bouncycastle.crypto.io.CipherOutputStream(underlyingOutputStream, cipher);
  }

  @Override
  public InputStream newCipherInputStream(InputStream underlyingInputStream, byte[] secretKey, byte[] iv) throws CipherException {
    AEADBlockCipher cipher = new GCMBlockCipher(new TwofishEngine());
    cipher.init(false, new AEADParameters(new KeyParameter(secretKey), MAC_SIZE, iv));
   
    return new org.bouncycastle.crypto.io.CipherInputStream(underlyingInputStream, cipher);
  }
View Full Code Here

Examples of org.bouncycastle.crypto.modes.GCMBlockCipher

    super(id, algorithm, keySize, ivSize, needsUnlimitedStrength);
  }
   
  @Override
  public OutputStream newCipherOutputStream(OutputStream underlyingOutputStream, byte[] secretKey, byte[] iv) throws CipherException {
    AEADBlockCipher cipher = new GCMBlockCipher(new AESEngine());
    cipher.init(true, new AEADParameters(new KeyParameter(secretKey), MAC_SIZE, iv));
   
    return new org.bouncycastle.crypto.io.CipherOutputStream(underlyingOutputStream, cipher);
  }
View Full Code Here

Examples of org.bouncycastle.crypto.modes.GCMBlockCipher

    return new org.bouncycastle.crypto.io.CipherOutputStream(underlyingOutputStream, cipher);
  }

  @Override
  public InputStream newCipherInputStream(InputStream underlyingInputStream, byte[] secretKey, byte[] iv) throws CipherException {
    AEADBlockCipher cipher = new GCMBlockCipher(new AESEngine());
    cipher.init(false, new AEADParameters(new KeyParameter(secretKey), MAC_SIZE, iv));
   
    return new org.bouncycastle.crypto.io.CipherInputStream(underlyingInputStream, cipher);
  }
View Full Code Here

Examples of org.bouncycastle.crypto.modes.GCMBlockCipher

    // Initialise AES cipher
    BlockCipher cipher = AES.createCipher(kek, true);

    // Create GCM cipher with AES
    GCMBlockCipher gcm = new GCMBlockCipher(cipher);

    AEADParameters aeadParams = new AEADParameters(new KeyParameter(kek.getEncoded()),
      AUTH_TAG_BIT_LENGTH,
      iv,
      null);
    gcm.init(true, aeadParams);

    // Prepare output buffer
    int outputLength = gcm.getOutputSize(cek.getEncoded().length);
    byte[] output = new byte[outputLength];

    // Produce cipher text
    int outputOffset = gcm.processBytes(cek.getEncoded(), 0, cek.getEncoded().length, output, 0);

    // Produce authentication tag
    try {
      outputOffset += gcm.doFinal(output, outputOffset);

    } catch (InvalidCipherTextException e) {

      throw new JOSEException("Couldn't generate GCM authentication tag for key: " + e.getMessage(), e);
    }
View Full Code Here

Examples of org.bouncycastle.crypto.modes.GCMBlockCipher

    // Initialise AES cipher
    BlockCipher cipher = AES.createCipher(kek, false);

    // Create GCM cipher with AES
    GCMBlockCipher gcm = new GCMBlockCipher(cipher);

    AEADParameters aeadParams = new AEADParameters(new KeyParameter(kek.getEncoded()),
      AUTH_TAG_BIT_LENGTH,
      iv,
      null);
    gcm.init(false, aeadParams);

    byte[] cipherText = authEncrCEK.getCipherText();
    byte[] authTag = authEncrCEK.getAuthenticationTag();

    // Join encrypted CEK and authentication tag to produce cipher input
    byte[] input = new byte[cipherText.length + authTag.length];

    System.arraycopy(cipherText, 0, input, 0, cipherText.length);
    System.arraycopy(authTag, 0, input, cipherText.length, authTag.length);

    int keyBytesLength = gcm.getOutputSize(input.length);

    byte[] keyBytes = new byte[keyBytesLength];


    // Decrypt
    int keyBytesOffset = gcm.processBytes(input, 0, input.length, keyBytes, 0);


    // Validate authentication tag
    try {
      keyBytesOffset += gcm.doFinal(keyBytes, keyBytesOffset);

    } catch (InvalidCipherTextException e) {

      throw new JOSEException("Couldn't validate GCM authentication tag: " + e.getMessage(), e);
    }
View Full Code Here

Examples of org.bouncycastle.crypto.modes.GCMBlockCipher

    // Initialise AES cipher
    BlockCipher cipher = AES.createCipher(secretKey, forEncryption);

    // Create GCM cipher with AES
    GCMBlockCipher gcm = new GCMBlockCipher(cipher);

    AEADParameters aeadParams = new AEADParameters(new KeyParameter(secretKey.getEncoded()),
                                             AUTH_TAG_BIT_LENGTH,
                                             iv,
                                             authData);
    gcm.init(forEncryption, aeadParams);

    return gcm;
  }
View Full Code Here

Examples of org.bouncycastle.crypto.modes.GCMBlockCipher

                                          final byte[] authData,
                                          final Provider provider)
    throws JOSEException {

    // Initialise AES/GCM cipher for encryption
    GCMBlockCipher cipher = createAESGCMCipher(secretKey, true, iv, authData);


    // Prepare output buffer
    int outputLength = cipher.getOutputSize(plainText.length);
    byte[] output = new byte[outputLength];


    // Produce cipher text
    int outputOffset = cipher.processBytes(plainText, 0, plainText.length, output, 0);


    // Produce authentication tag
    try {
      outputOffset += cipher.doFinal(output, outputOffset);

    } catch (InvalidCipherTextException e) {

      throw new JOSEException("Couldn't generate GCM authentication tag: " + e.getMessage(), e);
    }
View Full Code Here

Examples of org.bouncycastle.crypto.modes.GCMBlockCipher

                         final byte[] authTag,
                         final Provider provider)
    throws JOSEException {

    // Initialise AES/GCM cipher for decryption
    GCMBlockCipher cipher = createAESGCMCipher(secretKey, false, iv, authData);


    // Join cipher text and authentication tag to produce cipher input
    byte[] input = new byte[cipherText.length + authTag.length];

    System.arraycopy(cipherText, 0, input, 0, cipherText.length);
    System.arraycopy(authTag, 0, input, cipherText.length, authTag.length);

    int outputLength = cipher.getOutputSize(input.length);

    byte[] output = new byte[outputLength];


    // Decrypt
    int outputOffset = cipher.processBytes(input, 0, input.length, output, 0);

    // Validate authentication tag
    try {
      outputOffset += cipher.doFinal(output, outputOffset);
       
    } catch (InvalidCipherTextException e) {

      throw new JOSEException("Couldn't validate GCM authentication tag: " + e.getMessage(), e);
    }
View Full Code Here

Examples of org.bouncycastle2.crypto.modes.GCMBlockCipher

            cipher = new AEADGenericBlockCipher(new EAXBlockCipher(baseEngine));
        }
        else if (modeName.startsWith("GCM"))
        {
            ivLength = baseEngine.getBlockSize();
            cipher = new AEADGenericBlockCipher(new GCMBlockCipher(baseEngine));
        }
        else
        {
            throw new NoSuchAlgorithmException("can't support mode " + mode);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.