Search in sources :

Example 1 with BCBlockCipherBuilder

use of net.viperfish.journal.secureAlgs.BCBlockCipherEncryptor.BCBlockCipherBuilder in project vsDiaryWriter by shilongdai.

the class BlockCiphers method getEncryptor.

public static BlockCipherEncryptor getEncryptor(String cipher, String mode, String padding) {
    StringBuilder sb = new StringBuilder();
    sb.append(cipher).append("/").append(mode).append("/").append(padding);
    String type = sb.toString();
    BlockCipherEncryptor bc = cache.get(type);
    if (bc == null) {
        BlockCipher engine = getBlockCipherEngine(cipher);
        BlockCipher modeEngine = wrapBlockCipherMode(engine, mode);
        BlockCipherPadding pad = getBlockCipherPadding(padding);
        BCBlockCipherBuilder builder = new BCBlockCipherBuilder();
        builder.setBlockSize(engine.getBlockSize()).setKeySize(getKeySize(cipher)).setCipher(modeEngine).setPadding(pad);
        bc = builder.build();
        cache.put(type, bc);
    }
    return bc;
}
Also used : CBCBlockCipher(org.bouncycastle.crypto.modes.CBCBlockCipher) CFBBlockCipher(org.bouncycastle.crypto.modes.CFBBlockCipher) BlockCipher(org.bouncycastle.crypto.BlockCipher) OFBBlockCipher(org.bouncycastle.crypto.modes.OFBBlockCipher) SICBlockCipher(org.bouncycastle.crypto.modes.SICBlockCipher) BlockCipherPadding(org.bouncycastle.crypto.paddings.BlockCipherPadding) BCBlockCipherBuilder(net.viperfish.journal.secureAlgs.BCBlockCipherEncryptor.BCBlockCipherBuilder)

Aggregations

BCBlockCipherBuilder (net.viperfish.journal.secureAlgs.BCBlockCipherEncryptor.BCBlockCipherBuilder)1 BlockCipher (org.bouncycastle.crypto.BlockCipher)1 CBCBlockCipher (org.bouncycastle.crypto.modes.CBCBlockCipher)1 CFBBlockCipher (org.bouncycastle.crypto.modes.CFBBlockCipher)1 OFBBlockCipher (org.bouncycastle.crypto.modes.OFBBlockCipher)1 SICBlockCipher (org.bouncycastle.crypto.modes.SICBlockCipher)1 BlockCipherPadding (org.bouncycastle.crypto.paddings.BlockCipherPadding)1