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

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

Introduction

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

Prototype

Grain128Engine

Source Link

Usage

From source file:com.DSC.crypto.Cipher.java

License:Open Source License

/**
 * /*from   www .j  a va2s.  co m*/
 * @param symmetricKey
 * @param IV
 * @return
 */
public static byte[] encryptMsg(byte[] symmetricKey, byte[] IV, byte[] data) {
    byte[] cipherText = new byte[data.length];

    /* Grain stream cipher */
    StreamCipher grain = new Grain128Engine();

    /* Initialize stream cipher */
    ParametersWithIV param = new ParametersWithIV(new KeyParameter(symmetricKey), IV);
    grain.init(true, param);

    /* Encrypt the message */
    grain.processBytes(data, 0, data.length, cipherText, 0);
    return cipherText;
}

From source file:com.DSC.crypto.Cipher.java

License:Open Source License

/**
 * /*from  w ww .  j av  a  2 s  .  c  om*/
 * @param symmetricKey
 * @param IV
 * @return
 */
public static byte[] decryptMsg(byte[] symmetricKey, byte[] IV, byte[] data) {
    byte[] cipherText = new byte[data.length];

    /* Grain stream cipher */
    StreamCipher grain = new Grain128Engine();

    /* Initialize stream cipher */
    ParametersWithIV param = new ParametersWithIV(new KeyParameter(symmetricKey), IV);
    grain.init(false, param);

    /* Decrypt the message */
    grain.processBytes(data, 0, data.length, cipherText, 0);
    return cipherText;
}

From source file:org.cryptacular.spec.StreamCipherSpec.java

License:Open Source License

@Override
public StreamCipher newInstance() {
    StreamCipher cipher;// w  w w.  j av a  2 s.co  m
    if ("Grainv1".equalsIgnoreCase(algorithm) || "Grain-v1".equalsIgnoreCase(algorithm)) {
        cipher = new ISAACEngine();
    } else if ("Grain128".equalsIgnoreCase(algorithm) || "Grain-128".equalsIgnoreCase(algorithm)) {
        cipher = new Grain128Engine();
    } else if ("ISAAC".equalsIgnoreCase(algorithm)) {
        cipher = new ISAACEngine();
    } else if ("HC128".equalsIgnoreCase(algorithm)) {
        cipher = new HC128Engine();
    } else if ("HC256".equalsIgnoreCase(algorithm)) {
        cipher = new HC256Engine();
    } else if ("RC4".equalsIgnoreCase(algorithm)) {
        cipher = new RC4Engine();
    } else if ("Salsa20".equalsIgnoreCase(algorithm)) {
        cipher = new Salsa20Engine();
    } else if ("VMPC".equalsIgnoreCase(algorithm)) {
        cipher = new VMPCEngine();
    } else {
        throw new IllegalStateException("Unsupported cipher algorithm " + algorithm);
    }
    return cipher;
}