Search in sources :

Example 1 with CFBBlockCipher

use of org.bouncycastle.crypto.modes.CFBBlockCipher in project robovm by robovm.

the class BaseBlockCipher method engineSetMode.

protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
    modeName = Strings.toUpperCase(mode);
    if (modeName.equals("ECB")) {
        ivLength = 0;
        cipher = new BufferedGenericBlockCipher(baseEngine);
    } else if (modeName.equals("CBC")) {
        ivLength = baseEngine.getBlockSize();
        cipher = new BufferedGenericBlockCipher(new CBCBlockCipher(baseEngine));
    } else if (modeName.startsWith("OFB")) {
        ivLength = baseEngine.getBlockSize();
        if (modeName.length() != 3) {
            int wordSize = Integer.parseInt(modeName.substring(3));
            cipher = new BufferedGenericBlockCipher(new OFBBlockCipher(baseEngine, wordSize));
        } else {
            cipher = new BufferedGenericBlockCipher(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 BufferedGenericBlockCipher(new CFBBlockCipher(baseEngine, wordSize));
        } else {
            cipher = new BufferedGenericBlockCipher(new CFBBlockCipher(baseEngine, 8 * baseEngine.getBlockSize()));
        }
    } else // END android-removed
    if (modeName.startsWith("SIC")) {
        ivLength = baseEngine.getBlockSize();
        if (ivLength < 16) {
            throw new IllegalArgumentException("Warning: SIC-Mode can become a twotime-pad if the blocksize of the cipher is too small. Use a cipher with a block size of at least 128 bits (e.g. AES)");
        }
        cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(new SICBlockCipher(baseEngine)));
    } else if (modeName.startsWith("CTR")) {
        ivLength = baseEngine.getBlockSize();
        cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(new SICBlockCipher(baseEngine)));
    } else // END android-removed
    if (modeName.startsWith("CTS")) {
        ivLength = baseEngine.getBlockSize();
        cipher = new BufferedGenericBlockCipher(new CTSBlockCipher(new CBCBlockCipher(baseEngine)));
    } else if (modeName.startsWith("CCM")) {
        ivLength = baseEngine.getBlockSize();
        cipher = new AEADGenericBlockCipher(new CCMBlockCipher(baseEngine));
    } else // END android-removed
    if (modeName.startsWith("GCM")) {
        ivLength = baseEngine.getBlockSize();
        cipher = new AEADGenericBlockCipher(new GCMBlockCipher(baseEngine));
    } else {
        throw new NoSuchAlgorithmException("can't support mode " + mode);
    }
}
Also used : OFBBlockCipher(org.bouncycastle.crypto.modes.OFBBlockCipher) CCMBlockCipher(org.bouncycastle.crypto.modes.CCMBlockCipher) SICBlockCipher(org.bouncycastle.crypto.modes.SICBlockCipher) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CFBBlockCipher(org.bouncycastle.crypto.modes.CFBBlockCipher) BufferedBlockCipher(org.bouncycastle.crypto.BufferedBlockCipher) PaddedBufferedBlockCipher(org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher) CTSBlockCipher(org.bouncycastle.crypto.modes.CTSBlockCipher) CBCBlockCipher(org.bouncycastle.crypto.modes.CBCBlockCipher) GCMBlockCipher(org.bouncycastle.crypto.modes.GCMBlockCipher)

Example 2 with CFBBlockCipher

use of org.bouncycastle.crypto.modes.CFBBlockCipher in project ProxProx by GoMint.

the class EncryptionHandler method createCipher.

private BufferedBlockCipher createCipher(boolean encryptor, byte[] key, byte[] iv) {
    BufferedBlockCipher cipher = new BufferedBlockCipher(new CFBBlockCipher(new AESFastEngine(), 8));
    cipher.init(encryptor, new ParametersWithIV(new KeyParameter(key), iv));
    return cipher;
}
Also used : ParametersWithIV(org.bouncycastle.crypto.params.ParametersWithIV) CFBBlockCipher(org.bouncycastle.crypto.modes.CFBBlockCipher) BufferedBlockCipher(org.bouncycastle.crypto.BufferedBlockCipher) KeyParameter(org.bouncycastle.crypto.params.KeyParameter) AESFastEngine(org.bouncycastle.crypto.engines.AESFastEngine)

Example 3 with CFBBlockCipher

use of org.bouncycastle.crypto.modes.CFBBlockCipher in project rxlib by RockyLOMO.

the class BlowFishCrypt method getCipher.

@Override
protected StreamBlockCipher getCipher(boolean isEncrypted) throws InvalidAlgorithmParameterException {
    BlowfishEngine engine = new BlowfishEngine();
    StreamBlockCipher cipher;
    if (_name.equals(CIPHER_BLOWFISH_CFB)) {
        cipher = new CFBBlockCipher(engine, getIVLength() * 8);
    } else {
        throw new InvalidAlgorithmParameterException(_name);
    }
    return cipher;
}
Also used : StreamBlockCipher(org.bouncycastle.crypto.StreamBlockCipher) CFBBlockCipher(org.bouncycastle.crypto.modes.CFBBlockCipher) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) BlowfishEngine(org.bouncycastle.crypto.engines.BlowfishEngine)

Example 4 with CFBBlockCipher

use of org.bouncycastle.crypto.modes.CFBBlockCipher in project rxlib by RockyLOMO.

the class AesCrypt method getCipher.

@Override
protected StreamBlockCipher getCipher(boolean isEncrypted) throws InvalidAlgorithmParameterException {
    AESFastEngine engine = new AESFastEngine();
    StreamBlockCipher cipher;
    if (_name.equals(CIPHER_AES_128_CFB)) {
        cipher = new CFBBlockCipher(engine, getIVLength() * 8);
    } else if (_name.equals(CIPHER_AES_192_CFB)) {
        cipher = new CFBBlockCipher(engine, getIVLength() * 8);
    } else if (_name.equals(CIPHER_AES_256_CFB)) {
        cipher = new CFBBlockCipher(engine, getIVLength() * 8);
    } else if (_name.equals(CIPHER_AES_128_OFB)) {
        cipher = new OFBBlockCipher(engine, getIVLength() * 8);
    } else if (_name.equals(CIPHER_AES_192_OFB)) {
        cipher = new OFBBlockCipher(engine, getIVLength() * 8);
    } else if (_name.equals(CIPHER_AES_256_OFB)) {
        cipher = new OFBBlockCipher(engine, getIVLength() * 8);
    } else {
        throw new InvalidAlgorithmParameterException(_name);
    }
    return cipher;
}
Also used : StreamBlockCipher(org.bouncycastle.crypto.StreamBlockCipher) OFBBlockCipher(org.bouncycastle.crypto.modes.OFBBlockCipher) CFBBlockCipher(org.bouncycastle.crypto.modes.CFBBlockCipher) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) AESFastEngine(org.bouncycastle.crypto.engines.AESFastEngine)

Example 5 with CFBBlockCipher

use of org.bouncycastle.crypto.modes.CFBBlockCipher in project keepass2android by PhilippC.

the class JCEBlockCipher method engineSetMode.

protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
    modeName = Strings.toUpperCase(mode);
    if (modeName.equals("ECB")) {
        ivLength = 0;
        cipher = new BufferedGenericBlockCipher(baseEngine);
    } else if (modeName.equals("CBC")) {
        ivLength = baseEngine.getBlockSize();
        cipher = new BufferedGenericBlockCipher(new CBCBlockCipher(baseEngine));
    } else if (modeName.startsWith("OFB")) {
        ivLength = baseEngine.getBlockSize();
        if (modeName.length() != 3) {
            int wordSize = Integer.parseInt(modeName.substring(3));
            cipher = new BufferedGenericBlockCipher(new OFBBlockCipher(baseEngine, wordSize));
        } else {
            cipher = new BufferedGenericBlockCipher(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 BufferedGenericBlockCipher(new CFBBlockCipher(baseEngine, wordSize));
        } else {
            cipher = new BufferedGenericBlockCipher(new CFBBlockCipher(baseEngine, 8 * baseEngine.getBlockSize()));
        }
    } else /*
        else if (modeName.startsWith("PGP"))
        {
            boolean inlineIV = modeName.equalsIgnoreCase("PGPCFBwithIV");

            ivLength = baseEngine.getBlockSize();
            cipher = new BufferedGenericBlockCipher(
                new PGPCFBBlockCipher(baseEngine, inlineIV));
        }
        else if (modeName.equalsIgnoreCase("OpenPGPCFB"))
        {
            ivLength = 0;
            cipher = new BufferedGenericBlockCipher(
                new OpenPGPCFBBlockCipher(baseEngine));
        }
        else if (modeName.startsWith("SIC"))
        {
            ivLength = baseEngine.getBlockSize();
            if (ivLength < 16)
            {
                throw new IllegalArgumentException("Warning: SIC-Mode can become a twotime-pad if the blocksize of the cipher is too small. Use a cipher with a block size of at least 128 bits (e.g. AES)");
            }
            cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(
                        new SICBlockCipher(baseEngine)));
        }
        else if (modeName.startsWith("CTR"))
        {
            ivLength = baseEngine.getBlockSize();
            cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(
                        new SICBlockCipher(baseEngine)));
        }
        else if (modeName.startsWith("GOFB"))
        {
            ivLength = baseEngine.getBlockSize();
            cipher = new BufferedGenericBlockCipher(new BufferedBlockCipher(
                        new GOFBBlockCipher(baseEngine)));
        }
        else if (modeName.startsWith("CTS"))
        {
            ivLength = baseEngine.getBlockSize();
            cipher = new BufferedGenericBlockCipher(new CTSBlockCipher(new CBCBlockCipher(baseEngine)));
        }
        else if (modeName.startsWith("CCM"))
        {
            ivLength = baseEngine.getBlockSize();
            cipher = new AEADGenericBlockCipher(new CCMBlockCipher(baseEngine));
        }
        else if (modeName.startsWith("EAX"))
        {
            ivLength = baseEngine.getBlockSize();
            cipher = new AEADGenericBlockCipher(new EAXBlockCipher(baseEngine));
        }
        else if (modeName.startsWith("GCM"))
        {
            ivLength = baseEngine.getBlockSize();
            cipher = new AEADGenericBlockCipher(new GCMBlockCipher(baseEngine));
        }
        */
    {
        throw new NoSuchAlgorithmException("can't support mode " + mode);
    }
}
Also used : OFBBlockCipher(org.bouncycastle.crypto.modes.OFBBlockCipher) CFBBlockCipher(org.bouncycastle.crypto.modes.CFBBlockCipher) CBCBlockCipher(org.bouncycastle.crypto.modes.CBCBlockCipher) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

CFBBlockCipher (org.bouncycastle.crypto.modes.CFBBlockCipher)8 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)4 StreamBlockCipher (org.bouncycastle.crypto.StreamBlockCipher)4 OFBBlockCipher (org.bouncycastle.crypto.modes.OFBBlockCipher)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 BufferedBlockCipher (org.bouncycastle.crypto.BufferedBlockCipher)3 CBCBlockCipher (org.bouncycastle.crypto.modes.CBCBlockCipher)3 AESFastEngine (org.bouncycastle.crypto.engines.AESFastEngine)2 CCMBlockCipher (org.bouncycastle.crypto.modes.CCMBlockCipher)2 CTSBlockCipher (org.bouncycastle.crypto.modes.CTSBlockCipher)2 GCMBlockCipher (org.bouncycastle.crypto.modes.GCMBlockCipher)2 SICBlockCipher (org.bouncycastle.crypto.modes.SICBlockCipher)2 PaddedBufferedBlockCipher (org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher)2 BlowfishEngine (org.bouncycastle.crypto.engines.BlowfishEngine)1 CamelliaEngine (org.bouncycastle.crypto.engines.CamelliaEngine)1 SEEDEngine (org.bouncycastle.crypto.engines.SEEDEngine)1 GOFBBlockCipher (org.bouncycastle.crypto.modes.GOFBBlockCipher)1 KeyParameter (org.bouncycastle.crypto.params.KeyParameter)1 ParametersWithIV (org.bouncycastle.crypto.params.ParametersWithIV)1