Package org.bouncycastle.crypto.paddings

Examples of org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher


   
    /** 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


      throws DataLengthException, IllegalStateException, InvalidCipherTextException {

    // set up engine, block cipher mode and padding
    AESEngine aesEngine = new AESEngine();
    CBCBlockCipher cbc = new CBCBlockCipher(aesEngine);
    PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(cbc);

    // apply parameters
    CipherParameters parameters = new ParametersWithIV(new KeyParameter(key.getEncoded()), initVector);
    cipher.init(forEncrypting, parameters);

    // process ciphering
    byte[] output = new byte[cipher.getOutputSize(data.length)];

    int bytesProcessed1 = cipher.processBytes(data, 0, data.length, output, 0);
    int bytesProcessed2 = cipher.doFinal(output, bytesProcessed1);

    byte[] result = new byte[bytesProcessed1 + bytesProcessed2];
    System.arraycopy(output, 0, result, 0, result.length);
    return result;
  }
View Full Code Here

    }

    private BufferedBlockCipher createCipher(boolean encrypt) throws Exception {
        AESEngine blockCipher = new AESEngine();
        CBCBlockCipher cbcCipher = new CBCBlockCipher(blockCipher);
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(cbcCipher);
        CipherParameters params = createCipherParams();
        cipher.init(encrypt, params);
        return cipher;
    }
View Full Code Here

    protected abstract PBEParametersGenerator createPBEParametersGenerator();

    private BufferedBlockCipher createCipher(boolean encrypt) {
        AESEngine blockCipher = new AESEngine();
        CBCBlockCipher cbcCipher = new CBCBlockCipher(blockCipher);
        BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(cbcCipher);
        CipherParameters params = createCipherParams();
        cipher.init(encrypt, params);
        return cipher;
    }
View Full Code Here

   
    /** 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

    protected JCEBlockCipher(
        BlockCipher engine)
    {
        baseEngine = engine;

        cipher = new PaddedBufferedBlockCipher(engine);
    }
View Full Code Here

        BlockCipher engine,
        int         ivLength)
    {
        baseEngine = engine;

        this.cipher = new PaddedBufferedBlockCipher(engine);
        this.ivLength = ivLength / 8;
    }
View Full Code Here

        modeName = Strings.toUpperCase(mode);

        if (modeName.equals("ECB"))
        {
            ivLength = 0;
            cipher = new PaddedBufferedBlockCipher(baseEngine);
        }
        else if (modeName.equals("CBC"))
        {
            ivLength = baseEngine.getBlockSize();
            cipher = new PaddedBufferedBlockCipher(
                            new CBCBlockCipher(baseEngine));
        }
        else if (modeName.startsWith("OFB"))
        {
            ivLength = baseEngine.getBlockSize();
            if (modeName.length() != 3)
            {
                int wordSize = Integer.parseInt(modeName.substring(3));

                cipher = new PaddedBufferedBlockCipher(
                                new OFBBlockCipher(baseEngine, wordSize));
            }
            else
            {
                cipher = new PaddedBufferedBlockCipher(
                        new OFBBlockCipher(baseEngine, 8 * baseEngine.getBlockSize()));
            }
        }
        else if (modeName.startsWith("CFB"))
        {
            ivLength = baseEngine.getBlockSize();
            if (modeName.length() != 3)
            {
                int wordSize = Integer.parseInt(modeName.substring(3));

                cipher = new PaddedBufferedBlockCipher(
                                new CFBBlockCipher(baseEngine, wordSize));
            }
            else
            {
                cipher = new PaddedBufferedBlockCipher(
                        new CFBBlockCipher(baseEngine, 8 * baseEngine.getBlockSize()));
            }
        }
        else if (modeName.startsWith("PGP"))
        {
            if (modeName.equalsIgnoreCase("PGPCFBwithIV"))
            {
                ivLength = baseEngine.getBlockSize();
                cipher = new PaddedBufferedBlockCipher(
                    new PGPCFBBlockCipher(baseEngine, true));
            }
            else
            {
                ivLength = baseEngine.getBlockSize();
                cipher = new PaddedBufferedBlockCipher(
                    new PGPCFBBlockCipher(baseEngine, false));
            }
        }
        else if (modeName.equalsIgnoreCase("OpenPGPCFB"))
        {
            ivLength = 0;
            cipher = new PaddedBufferedBlockCipher(
                new OpenPGPCFBBlockCipher(baseEngine));
        }
        else if (modeName.startsWith("SIC"))
        {
            ivLength = baseEngine.getBlockSize();
View Full Code Here

                cipher = new BufferedBlockCipher(cipher.getUnderlyingCipher());
            }
        }
        else if (paddingName.equals("PKCS5PADDING") || paddingName.equals("PKCS7PADDING"))
        {
            cipher = new PaddedBufferedBlockCipher(cipher.getUnderlyingCipher());
        }
        else if (paddingName.equals("ZEROBYTEPADDING"))
        {
            cipher = new PaddedBufferedBlockCipher(cipher.getUnderlyingCipher(), new ZeroBytePadding());
        }
        else if (paddingName.equals("ISO10126PADDING") || paddingName.equals("ISO10126-2PADDING"))
        {
            cipher = new PaddedBufferedBlockCipher(cipher.getUnderlyingCipher(), new ISO10126d2Padding());
        }
        else if (paddingName.equals("X9.23PADDING") || paddingName.equals("X923PADDING"))
        {
            cipher = new PaddedBufferedBlockCipher(cipher.getUnderlyingCipher(), new X923Padding());
        }
        else if (paddingName.equals("ISO7816-4PADDING") || paddingName.equals("ISO9797-1PADDING"))
        {
            cipher = new PaddedBufferedBlockCipher(cipher.getUnderlyingCipher(), new ISO7816d4Padding());
        }
        else if (paddingName.equals("TBCPADDING"))
        {
            cipher = new PaddedBufferedBlockCipher(cipher.getUnderlyingCipher(), new TBCPadding());
        }
        else if (paddingName.equals("WITHCTS"))
        {
            padded = false;
            cipher = new CTSBlockCipher(cipher.getUnderlyingCipher());
View Full Code Here

TOP

Related Classes of org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher

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.