Package org.bouncycastle.crypto

Examples of org.bouncycastle.crypto.BlockCipher


    {
        try
        {
            if (secKeyData != null && secKeyData.length > 0)
            {
                BlockCipher engine = BcImplProvider.createBlockCipher(keyAlgorithm);
                BufferedBlockCipher cipher = BcUtil.createSymmetricKeyWrapper(false, engine, key, new byte[engine.getBlockSize()]);

                byte[] out = new byte[secKeyData.length];

                int len = cipher.processBytes(secKeyData, 0, secKeyData.length, out, 0);
View Full Code Here


    }

    public PGPDataDecryptor createDataDecryptor(boolean withIntegrityPacket, int encAlgorithm, byte[] key)
        throws PGPException
    {
        BlockCipher engine = BcImplProvider.createBlockCipher(encAlgorithm);

        return BcUtil.createDataDecryptor(withIntegrityPacket, engine, key);
    }
View Full Code Here

        byte[] returnKey = new byte[ELength];
       
        try{

            //setup Cipher
            BlockCipher cbc = new CBCBlockCipher(new AESFastEngine());
            cbc.init(false, new KeyParameter(key));

            //translate bytes
            int nextBlockSize;
            for(int i=0;i<ELength;i=i+nextBlockSize){
                cbc.processBlock(rawValue, i, returnKey, i);
                nextBlockSize=cbc.getBlockSize();
            }
           
        }catch(Exception e){
            throw new PdfSecurityException("Exception "+e.getMessage()+" with v5 encoding");
        }
View Full Code Here

public class AESCipher {
    private PaddedBufferedBlockCipher bp;
   
    /** Creates a new instance of AESCipher */
    public AESCipher(boolean forEncryption, byte[] key, byte[] iv) {
        BlockCipher aes = new AESFastEngine();
        BlockCipher cbc = new CBCBlockCipher(aes);
        bp = new PaddedBufferedBlockCipher(cbc);
        KeyParameter kp = new KeyParameter(key);
        ParametersWithIV piv = new ParametersWithIV(kp, iv);
        bp.init(forEncryption, piv);
    }
View Full Code Here

public class AESCipher {
    private PaddedBufferedBlockCipher bp;
   
    /** Creates a new instance of AESCipher */
    public AESCipher(boolean forEncryption, byte[] key, byte[] iv) {
        BlockCipher aes = new AESFastEngine();
        BlockCipher cbc = new CBCBlockCipher(aes);
        bp = new PaddedBufferedBlockCipher(cbc);
        KeyParameter kp = new KeyParameter(key);
        ParametersWithIV piv = new ParametersWithIV(kp, iv);
        bp.init(forEncryption, piv);
    }
View Full Code Here

                                             final boolean forEncryption,
                                             final byte[] iv,
                                             final byte[] authData) {

    // 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()),
View Full Code Here

public class AESCipher {
    private PaddedBufferedBlockCipher bp;
   
    /** Creates a new instance of AESCipher */
    public AESCipher(boolean forEncryption, byte[] key, byte[] iv) {
        BlockCipher aes = new AESFastEngine();
        BlockCipher cbc = new CBCBlockCipher(aes);
        bp = new PaddedBufferedBlockCipher(cbc);
        KeyParameter kp = new KeyParameter(key);
        ParametersWithIV piv = new ParametersWithIV(kp, iv);
        bp.init(forEncryption, piv);
    }
View Full Code Here

public class AESCipherCBCnoPad {
    private BlockCipher cbc;
   
    /** Creates a new instance of AESCipher */
    public AESCipherCBCnoPad(boolean forEncryption, byte[] key) {
        BlockCipher aes = new AESFastEngine();
        cbc = new CBCBlockCipher(aes);
        KeyParameter kp = new KeyParameter(key);
        cbc.init(forEncryption, kp);
    }
View Full Code Here

        if (params == null)
        {
            throw new IllegalStateException("CCM cipher unitialized.");
        }
       
        BlockCipher ctrCipher = new SICBlockCipher(cipher);
        byte[] iv = new byte[blockSize];
        byte[] nonce = params.getNonce();
        int    macSize = params.getMacSize() / 8;
        byte[] out;

        iv[0] = (byte)(((15 - nonce.length) - 1) & 0x7);
       
        System.arraycopy(nonce, 0, iv, 1, nonce.length);
       
        ctrCipher.init(forEncryption, new ParametersWithIV(params.getKey(), iv));
       
        if (forEncryption)
        {
            int index = inOff;
            int outOff = 0;
           
            out = new byte[inLen + macSize];
           
            calculateMac(in, inOff, inLen, macBlock);
           
            ctrCipher.processBlock(macBlock, 0, macBlock, 0);   // S0
           
            while (index < inLen - blockSize)                   // S1...
            {
                ctrCipher.processBlock(in, index, out, outOff);
                outOff += blockSize;
                index += blockSize;
            }
           
            byte[] block = new byte[blockSize];
           
            System.arraycopy(in, index, block, 0, inLen - index);
           
            ctrCipher.processBlock(block, 0, block, 0);
           
            System.arraycopy(block, 0, out, outOff, inLen - index);
           
            outOff += inLen - index;

            System.arraycopy(macBlock, 0, out, outOff, out.length - outOff);
        }
        else
        {
            int index = inOff;
            int outOff = 0;
           
            out = new byte[inLen - macSize];
           
            System.arraycopy(in, inOff + inLen - macSize, macBlock, 0, macSize);
           
            ctrCipher.processBlock(macBlock, 0, macBlock, 0);
           
            for (int i = macSize; i != macBlock.length; i++)
            {
                macBlock[i] = 0;
            }
           
            while (outOff < out.length - blockSize)
            {
                ctrCipher.processBlock(in, index, out, outOff);
                outOff += blockSize;
                index += blockSize;
            }
           
            byte[] block = new byte[blockSize];
           
            System.arraycopy(in, index, block, 0, out.length - outOff);
           
            ctrCipher.processBlock(block, 0, block, 0);
           
            System.arraycopy(block, 0, out, outOff, out.length - outOff);
           
            byte[] calculatedMacBlock = new byte[blockSize];
           
View Full Code Here

               final SecretKey kek,
               Provider provider)
    throws JOSEException {

    // 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()),
View Full Code Here

TOP

Related Classes of org.bouncycastle.crypto.BlockCipher

Copyright © 2018 www.massapicom. 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.