Example usage for org.bouncycastle.crypto.modes OFBBlockCipher OFBBlockCipher

List of usage examples for org.bouncycastle.crypto.modes OFBBlockCipher OFBBlockCipher

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.modes OFBBlockCipher OFBBlockCipher.

Prototype

public OFBBlockCipher(BlockCipher cipher, int blockSize) 

Source Link

Document

Basic constructor.

Usage

From source file:cc.agentx.security.AesCipher.java

License:Apache License

/**
 * <b>Notice: </b><br/>
 * 1. the <code>AESFastEngine</code> was replaced by <code>AESEngine</code> now.<br/>
 * 2. in <code>new CFBBlockCipher(engine, <b>16</b> * 8);</code> the IV length (16) is
 * reference to the shadowsocks's design.
 *
 * @see <a href="https://www.bouncycastle.org/releasenotes.html">
 * https://www.bouncycastle.org/releasenotes.html</a>#CVE-2016-1000339<br/>
 * <a href="https://shadowsocks.org/en/spec/cipher.html">
 * https://shadowsocks.org/en/spec/cipher.html</a>#Cipher
 *//*w  ww . jav  a 2s  . c  o  m*/
public AesCipher(String password, int mode) {
    key = new SecretKeySpec(password.getBytes(), "AES");
    keyLength = Math.abs(mode);
    AESEngine engine = new AESEngine();
    if (mode > 0) {
        cipher = new CFBBlockCipher(engine, 16 * 8);
    } else {
        cipher = new OFBBlockCipher(engine, 16 * 8);
    }
}

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

License:Open Source License

/**
 * Creates a new buffered block cipher from the specification in this
 * instance./*from ww w.  j  a  v a  2 s .c o m*/
 *
 * @return  New buffered block cipher instance.
 */
@Override
public BufferedBlockCipher newInstance() {
    BlockCipher cipher = getBlockCipherSpec().newInstance();

    switch (mode) {

    case "CBC":
        cipher = new CBCBlockCipher(cipher);
        break;

    case "OFB":
        cipher = new OFBBlockCipher(cipher, cipher.getBlockSize());
        break;

    case "CFB":
        cipher = new CFBBlockCipher(cipher, cipher.getBlockSize());
        break;

    default:
        break;
    }

    if (padding != null) {
        return new PaddedBufferedBlockCipher(cipher, getPadding(padding));
    }
    return new BufferedBlockCipher(cipher);
}

From source file:org.cryptacular.util.CipherUtilTest.java

License:Open Source License

@DataProvider(name = "block-cipher")
public Object[][] getBlockCipherData() {
    return new Object[][] { new Object[] {
            // Plaintext is NOT multiple of block size
            "Able was I ere I saw elba.", new CBCBlockCipher(new AESEngine()), new RBGNonce(16), },
            // Plaintext is multiple of block size
            new Object[] { "Four score and seven years ago, our forefathers ",
                    new CBCBlockCipher(new BlowfishEngine()), new RBGNonce(8), },
            // OFB
            new Object[] { "Have you passed through this night?", new OFBBlockCipher(new BlowfishEngine(), 64),
                    new LongCounterNonce(), },
            // CFB
            new Object[] {
                    "I went to the woods because I wished to live deliberately, to "
                            + "front only the essential facts of life",
                    new CFBBlockCipher(new AESEngine(), 128), new RBGNonce(16), }, };
}

From source file:shadowsocks.crypto.AESCrypto.java

License:Apache License

protected StreamBlockCipher getCipher(boolean isEncrypted) throws CryptoException {
    AESEngine engine = new AESEngine();
    StreamBlockCipher cipher;//from   w  w  w.j a  va2 s  . c  o  m

    if (mName.equals(CIPHER_AES_128_CFB)) {
        cipher = new CFBBlockCipher(engine, getIVLength() * 8);
    } else if (mName.equals(CIPHER_AES_192_CFB)) {
        cipher = new CFBBlockCipher(engine, getIVLength() * 8);
    } else if (mName.equals(CIPHER_AES_256_CFB)) {
        cipher = new CFBBlockCipher(engine, getIVLength() * 8);
    } else if (mName.equals(CIPHER_AES_128_OFB)) {
        cipher = new OFBBlockCipher(engine, getIVLength() * 8);
    } else if (mName.equals(CIPHER_AES_192_OFB)) {
        cipher = new OFBBlockCipher(engine, getIVLength() * 8);
    } else if (mName.equals(CIPHER_AES_256_OFB)) {
        cipher = new OFBBlockCipher(engine, getIVLength() * 8);
    } else {
        throw new CryptoException("Invalid AlgorithmParameter: " + mName);
    }

    return cipher;
}