List of usage examples for org.bouncycastle.crypto.modes CFBBlockCipher CFBBlockCipher
public CFBBlockCipher(BlockCipher cipher, int bitBlockSize)
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 *///from w ww. j a v a 2 s. c om 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:cc.agentx.security.BlowfishCipher.java
License:Apache License
/** * <b>Notice: </b><br/> * 1. in <code>new CFBBlockCipher(engine, <b>8</b> * 8);</code> the IV length (8) is * reference to the shadowsocks's design. * * @see <a href="https://shadowsocks.org/en/spec/cipher.html"> * https://shadowsocks.org/en/spec/cipher.html</a>#Cipher *//*from ww w .j av a2 s.c om*/ public BlowfishCipher(String password, int mode) { key = new SecretKeySpec(password.getBytes(), "BF"); keyLength = mode; BlowfishEngine engine = new BlowfishEngine(); cipher = new CFBBlockCipher(engine, 8 * 8); }
From source file:com.github.horrorho.inflatabledonkey.chunk.engine.ChunkDecrypters.java
License:Open Source License
public static Optional<byte[]> decrypt(byte[] key, byte[] data, int offset, int length) { StreamBlockCipher cipher = new CFBBlockCipher(new AESFastEngine(), 128); return decrypt(key, cipher, data, offset, length); }
From source file:com.github.horrorho.inflatabledonkey.chunk.engine.ChunkListDecrypter.java
License:Open Source License
CipherInputStream cipherInputStream(InputStream inputStream, byte[] key, byte[] checksum) { CFBBlockCipher cipher = new CFBBlockCipher(new AESFastEngine(), 128); KeyParameter keyParameter = new KeyParameter(key); cipher.init(false, keyParameter);//from ww w . j ava2s. co m return new CipherInputStream(inputStream, cipher); }
From source file:com.github.horrorho.liquiddonkey.cloud.store.ChunkDecrypter.java
License:Open Source License
/** * Returns a new instance./*from w w w . j a va 2 s .co m*/ * * @return a new instance, not null */ public static ChunkDecrypter create() { return new ChunkDecrypter(new CFBBlockCipher(new AESEngine(), 128), new SHA256Digest()); }
From source file:com.googlecode.jsendnsca.encryption.AESEncryptor.java
License:Apache License
public void encrypt(byte[] passiveCheckBytes, byte[] initVector, String password) { RijndaelEngine engine = new RijndaelEngine(_keyByteLength * 8); PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CFBBlockCipher(engine, 8), new ZeroBytePadding()); try {//from w w w.j a v a 2 s.c o m byte[] sessionKey = new byte[_keyByteLength]; byte[] passwordBytes = password.getBytes("US-ASCII"); System.arraycopy(passwordBytes, 0, sessionKey, 0, Math.min(_keyByteLength, passwordBytes.length)); byte[] iv = new byte[_keyByteLength]; System.arraycopy(initVector, 0, iv, 0, Math.min(_keyByteLength, initVector.length)); cipher.init(true, new ParametersWithIV(new KeyParameter(sessionKey), iv)); byte[] cipherText = new byte[cipher.getOutputSize(passiveCheckBytes.length)]; int cipherLength = cipher.processBytes(passiveCheckBytes, 0, passiveCheckBytes.length, cipherText, 0); cipherLength = cipherLength + cipher.doFinal(cipherText, cipherLength); int bytesToCopy = Math.min(passiveCheckBytes.length, cipherLength); System.arraycopy(cipherText, 0, passiveCheckBytes, 0, bytesToCopy); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.googlecode.jsendnsca.encryption.BlowfishEncryptor.java
License:Apache License
@Override public void encrypt(final byte[] passiveCheckBytes, final byte[] initVector, final String password) { final BlowfishEngine engine = new BlowfishEngine(); PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CFBBlockCipher(engine, 8), new ZeroBytePadding()); try {//from ww w . jav a 2 s . c o m final byte[] passwordBytes = password.getBytes("US-ASCII"); assertValidPasswordBytesLength(passwordBytes); final byte[] sessionKey = new byte[KEY_BYTES_LENGTH]; System.arraycopy(passwordBytes, 0, sessionKey, 0, Math.min(KEY_BYTES_LENGTH, passwordBytes.length)); final byte[] iv = new byte[KEY_BYTES_LENGTH]; System.arraycopy(initVector, 0, iv, 0, Math.min(KEY_BYTES_LENGTH, initVector.length)); cipher.init(true, new ParametersWithIV(new KeyParameter(sessionKey), iv)); final byte[] cipherText = new byte[cipher.getOutputSize(passiveCheckBytes.length)]; int cipherLength = cipher.processBytes(passiveCheckBytes, 0, passiveCheckBytes.length, cipherText, 0); cipherLength = cipherLength + cipher.doFinal(cipherText, cipherLength); final int bytesToCopy = Math.min(passiveCheckBytes.length, cipherLength); System.arraycopy(cipherText, 0, passiveCheckBytes, 0, bytesToCopy); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.raphfrk.craftproxyclient.net.protocol.p16x.P16xProtocol.java
License:Open Source License
private void enableEncryption(PacketChannel server, PacketChannel client, byte[] serverSecret, byte[] clientSecret) { BufferedBlockCipher outServer = new BufferedBlockCipher(new CFBBlockCipher(new AESEngine(), 8)); BufferedBlockCipher inServer = new BufferedBlockCipher(new CFBBlockCipher(new AESEngine(), 8)); CipherParameters paramsServer = new ParametersWithIV(new KeyParameter(serverSecret), serverSecret); outServer.init(true, paramsServer);//from ww w . j a v a 2 s.co m inServer.init(false, paramsServer); BufferedBlockCipher outClient = new BufferedBlockCipher(new CFBBlockCipher(new AESEngine(), 8)); BufferedBlockCipher inClient = new BufferedBlockCipher(new CFBBlockCipher(new AESEngine(), 8)); CipherParameters paramsClient = new ParametersWithIV(new KeyParameter(clientSecret), clientSecret); outClient.init(true, paramsClient); inClient.init(false, paramsClient); client.setWrappedChannel(new CryptByteChannelWrapper(client.getRawChannel(), outClient, inClient)); server.setWrappedChannel(new CryptByteChannelWrapper(server.getRawChannel(), outServer, inServer)); }
From source file:com.raphfrk.craftproxyclient.net.protocol.p17xlogin.P17xLoginProtocol.java
License:Open Source License
private void enableEncryption(PacketChannel server, PacketChannel client, byte[] secret) { BufferedBlockCipher out = new BufferedBlockCipher(new CFBBlockCipher(new AESEngine(), 8)); BufferedBlockCipher in = new BufferedBlockCipher(new CFBBlockCipher(new AESEngine(), 8)); CipherParameters params = new ParametersWithIV(new KeyParameter(secret), secret); out.init(true, params);//from w w w . j a va 2s . com in.init(false, params); // Unencrypted client.setWrappedChannel(client.getRawChannel()); // AES server.setWrappedChannel(new CryptByteChannelWrapper(server.getRawChannel(), out, in)); }
From source file:com.raphfrk.craftproxyliter.LocalSocket.java
License:Open Source License
public void setAES() { BufferedBlockCipher in = new BufferedBlockCipher(new CFBBlockCipher(new AESFastEngine(), 8)); in.init(false, new ParametersWithIV(new KeyParameter(this.ptc.getSecretKey().getEncoded()), this.ptc.getSecretKey().getEncoded(), 0, 16)); BufferedBlockCipher out = new BufferedBlockCipher(new CFBBlockCipher(new AESFastEngine(), 8)); out.init(true, new ParametersWithIV(new KeyParameter(this.ptc.getSecretKey().getEncoded()), this.ptc.getSecretKey().getEncoded(), 0, 16)); this.in = new DataInputStream(new CipherInputStream(this.in, in)); this.out = new DataOutputStream(new CipherOutputStream(this.out, out)); pin = new ProtocolInputStream(this.in, 255 * 16 * 1024); pout = new ProtocolOutputStream(this.out); }