Examples of BlockCipher


Examples of org.bouncycastle.crypto.BlockCipher

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

Examples of org.bouncycastle.crypto.BlockCipher

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

Examples of org.bouncycastle.crypto.BlockCipher

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

Examples of org.bouncycastle.crypto.BlockCipher

        byte[] iv = new byte[blockSize];
        iv[0] = (byte)((q - 1) & 0x7);
        System.arraycopy(nonce, 0, iv, 1, nonce.length);

        BlockCipher ctrCipher = new SICBlockCipher(cipher);
        ctrCipher.init(forEncryption, new ParametersWithIV(keyParam, iv));

        int index = inOff;
        int outOff = 0;
        byte[] output;

        if (forEncryption)
        {
            output = 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, output, 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, output, outOff, inLen - index);

            outOff += inLen - index;

            System.arraycopy(macBlock, 0, output, outOff, output.length - outOff);
        }
        else
        {
            output = 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 < output.length - blockSize)
            {
                ctrCipher.processBlock(in, index, output, outOff);
                outOff += blockSize;
                index += blockSize;
            }

            byte[] block = new byte[blockSize];

            System.arraycopy(in, index, block, 0, output.length - outOff);

            ctrCipher.processBlock(block, 0, block, 0);

            System.arraycopy(block, 0, output, outOff, output.length - outOff);

            byte[] calculatedMacBlock = new byte[blockSize];
View Full Code Here

Examples of org.bouncycastle.crypto.BlockCipher

        return password;
    }

    private BufferedBlockCipher getCipher() {
        if (cipher == null) {
            BlockCipher engine = new DESedeEngine();
            cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(engine));

            String name = cipher.getUnderlyingCipher().getAlgorithmName();
//            System.out.println("Using " + name);
        }
View Full Code Here

Examples of org.bouncycastle.crypto.BlockCipher

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

Examples of org.bouncycastle.crypto.BlockCipher

    protected byte[] encryptSessionInfo(int encAlgorithm, byte[] key, byte[] sessionInfo)
        throws PGPException
    {
        try
        {
            BlockCipher engine = BcImplProvider.createBlockCipher(encAlgorithm);
            BufferedBlockCipher cipher = BcUtil.createSymmetricKeyWrapper(true, engine, key, new byte[engine.getBlockSize()]);

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

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

Examples of org.bouncycastle.crypto.BlockCipher

    }

    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

Examples of org.bouncycastle.crypto.BlockCipher

    }

    static BlockCipher createBlockCipher(int encAlgorithm)
        throws PGPException
    {
        BlockCipher engine;

        switch (encAlgorithm)
        {
        case SymmetricKeyAlgorithmTags.AES_128:
        case SymmetricKeyAlgorithmTags.AES_192:
View Full Code Here

Examples of org.bouncycastle.crypto.BlockCipher

                    if (this.random == null)
                    {
                        this.random = new SecureRandom();
                    }

                    BlockCipher engine = BcImplProvider.createBlockCipher(this.encAlgorithm);

                    iv = new byte[engine.getBlockSize()];

                    this.random.nextBytes(iv);

                    BufferedBlockCipher c = BcUtil.createSymmetricKeyWrapper(true, engine, key, iv);
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.