Example usage for org.bouncycastle.crypto.engines AESEngine AESEngine

List of usage examples for org.bouncycastle.crypto.engines AESEngine AESEngine

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.engines AESEngine AESEngine.

Prototype

public AESEngine() 

Source Link

Document

default constructor - 128 bit block size.

Usage

From source file:dbn.crypto.Crypto.java

public static byte[] aesGCMDecrypt(byte[] ivCiphertext, byte[] key) {
    try {/*from   www .jav a  2  s. c o  m*/
        if (ivCiphertext.length < 16) {
            throw new InvalidCipherTextException("invalid ivCiphertext length");
        }
        byte[] iv = Arrays.copyOfRange(ivCiphertext, 0, 16);
        byte[] ciphertext = Arrays.copyOfRange(ivCiphertext, 16, ivCiphertext.length);
        GCMBlockCipher aes = new GCMBlockCipher(new AESEngine());
        CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
        aes.init(false, ivAndKey);
        byte[] output = new byte[aes.getOutputSize(ciphertext.length)];
        int plaintextLength = aes.processBytes(ciphertext, 0, ciphertext.length, output, 0);
        plaintextLength += aes.doFinal(output, plaintextLength);
        byte[] result = new byte[plaintextLength];
        System.arraycopy(output, 0, result, 0, result.length);
        return result;
    } catch (InvalidCipherTextException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:de.gs_sys.kp2016.crypto.SymmetricCipher.java

License:Open Source License

public static void setEngine(ENGINE e) {
    activeEngine = e;/*www  . j av a2  s .c  om*/
    switch (e) {
    case AES:
        engine = new AESEngine();
        break;
    //    case AES_WRAP:
    //        engine = new AESWrapEngine();
    //        break;
    case Rijndael:
        engine = new RijndaelEngine();
        break;
    case Camellia:
        engine = new CamelliaEngine();
        break;
    case Blowfish:
        engine = new BlowfishEngine();
        break;
    case Serpent:
        engine = new SerpentEngine();
        break;
    case Threefish:
        //engine = new ThreefishEngine(256);
        engine = new ThreefishEngine(ThreefishSize);
        break;
    case Twofish:
    default:
        engine = new TwofishEngine();
    }
}

From source file:de.gs_sys.kp2016.crypto.SymmetricCipher.java

License:Open Source License

@Deprecated
protected static BlockCipher getEngine(ENGINE engine) {
    switch (engine) {
    case AES:// w  w  w  .ja v  a 2 s. co m
        return new AESEngine();
    //    case AES_WRAP:
    //        return new AESWrapEngine();
    case Rijndael:
        return new RijndaelEngine();
    case Camellia:
        return new CamelliaEngine();
    case Blowfish:
        return new BlowfishEngine();
    case Serpent:
        return new SerpentEngine();
    case Threefish:
        // return new ThreefishEngine(256);
        return new ThreefishEngine(ThreefishSize);
    case Twofish:
    default:
        return new TwofishEngine();
    }
}

From source file:de.jpm.model.EncryptionService.java

License:Open Source License

/**
 *
 * @param password//from   ww w  . ja v  a2 s .  c o m
 */
public void initCipher(char[] password) {
    PBEParametersGenerator keyGenerator = new PKCS12ParametersGenerator(new SHA256Digest());
    keyGenerator.init(PKCS12ParametersGenerator.PKCS12PasswordToBytes(password), salt, 20);
    CipherParameters keyParams = keyGenerator.generateDerivedParameters(256, 128);

    encryptCipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), new PKCS7Padding());
    encryptCipher.init(true, keyParams);
    decryptCipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), new PKCS7Padding());
    decryptCipher.init(false, keyParams);
}

From source file:edu.biu.scapi.primitives.prf.bc.BcAES.java

License:Open Source License

/**
 * Passes the AESEngine of BC to the abstract super class
 */
public BcAES() {
    super(new AESEngine());

}

From source file:edu.biu.scapi.primitives.prf.bc.BcAES.java

License:Open Source License

/**
 * Receives random object to use./*from   w  ww.java 2s  . co m*/
 * Passes it and the DesedeEngine of BC to the abstract super class.
 * @param random SecureRandom to use
 */
public BcAES(SecureRandom random) {
    super(new AESEngine(), random);
}

From source file:edu.biu.scapi.primitives.prf.bc.BcAES.java

License:Open Source License

/**
 * Receives name of random algorithm to use.
 * Passes it and the AESEngine of BC to the abstract super class.
 * @param randNumGenAlg random algorithm to use
 * @throws NoSuchAlgorithmException //  w w w  . ja v  a2  s.c  o  m
 */
public BcAES(String randNumGenAlg) throws NoSuchAlgorithmException {
    super(new AESEngine(), SecureRandom.getInstance(randNumGenAlg));

}

From source file:edu.tamu.tcat.crypto.bouncycastle.SymmetricCipherBuilderImpl.java

License:Apache License

@Override
public SymmetricCipher buildCipher(Cipher cipher, Mode mode, boolean encryption, byte[] key, byte[] iv)
        throws CipherException {
    ParametersWithIV cipherParameters = new ParametersWithIV(new KeyParameter(key), iv);
    BlockCipher underlyingCipher = null;
    switch (cipher) {
    case AES128:/*from ww w  .j a v  a 2 s  . c  o  m*/
    case AES192:
    case AES256:
        underlyingCipher = new AESEngine();
        break;
    }
    BlockCipher blockCipher = null;
    switch (mode) {
    case CBC:
        blockCipher = new CBCBlockCipher(underlyingCipher);
        break;
    case GCM:
        throw new CipherException("GCM mode is authenticating encryption; use buildAEADCipher instead");
    }
    BufferedBlockCipher bufferedBlockCipher = new PaddedBufferedBlockCipher(blockCipher);
    bufferedBlockCipher.init(encryption, cipherParameters);

    return new BouncyCastleBlockCipher(bufferedBlockCipher);
}

From source file:edu.tamu.tcat.crypto.bouncycastle.SymmetricCipherBuilderImpl.java

License:Apache License

@Override
public AEADSymmetricCipher buildAEADCipher(Cipher cipher, Mode mode, boolean encryption, byte[] key, byte[] iv)
        throws CipherException {
    ParametersWithIV cipherParameters = new ParametersWithIV(new KeyParameter(key), iv);
    BlockCipher underlyingCipher = null;
    int macSize = 0;
    switch (cipher) {
    case AES128://from   w ww . j a  v a  2  s.  c om
    case AES192:
    case AES256:
        underlyingCipher = new AESEngine();
        break;
    }
    AEADBlockCipher aeadCipher = null;
    switch (mode) {
    case CBC:
        throw new CipherException(mode + " is not an authenticating encryption mode; use buildCipher instead");
    case GCM:
        aeadCipher = new GCMBlockCipher(underlyingCipher);
        macSize = underlyingCipher.getBlockSize();
        break;
    }
    aeadCipher.init(encryption, cipherParameters);

    return new BouncyCastleAEADCipher(aeadCipher, macSize, encryption);
}

From source file:fc.xml.xas.security.SecUtil.java

License:Open Source License

public static BufferedBlockCipher getCipher(String id) {
    Verifier.checkNotNull(id);/*from  w w  w  .  j  a  v  a 2 s . c  o  m*/
    if (id.equals(AES_128_CIPHER)) {
        return new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), new ISO10126d2Padding());
    } else {
        return null;
    }
}