本文整理汇总了Java中org.bouncycastle.crypto.StreamCipher类的典型用法代码示例。如果您正苦于以下问题:Java StreamCipher类的具体用法?Java StreamCipher怎么用?Java StreamCipher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StreamCipher类属于org.bouncycastle.crypto包,在下文中一共展示了StreamCipher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSalsa20
import org.bouncycastle.crypto.StreamCipher; //导入依赖的package包/类
private static StreamCipher getSalsa20(byte[] key) {
// Build stream cipher key
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
throw new RuntimeException("SHA 256 not supported");
}
byte[] key32 = md.digest(key);
KeyParameter keyParam = new KeyParameter(key32);
ParametersWithIV ivParam = new ParametersWithIV(keyParam, SALSA_IV);
StreamCipher cipher = new Salsa20Engine();
cipher.init(true, ivParam);
return cipher;
}
示例2: getCipher
import org.bouncycastle.crypto.StreamCipher; //导入依赖的package包/类
@Override
protected StreamCipher getCipher() {
String method = getMethod();
AESFastEngine engine = new AESFastEngine();
switch (method) {
case CIPHER_AES_128_CFB:
case CIPHER_AES_192_CFB:
case CIPHER_AES_256_CFB:
return new CFBBlockCipher(engine, 128);
case CIPHER_AES_128_CFB8:
case CIPHER_AES_192_CFB8:
case CIPHER_AES_256_CFB8:
return new CFBBlockCipher(engine, 8);
case CIPHER_AES_128_OFB:
case CIPHER_AES_192_OFB:
case CIPHER_AES_256_OFB:
return new OFBBlockCipher(engine, 128);
default:
throw new IllegalArgumentException(method);
}
}
示例3: reinitBug
import org.bouncycastle.crypto.StreamCipher; //导入依赖的package包/类
private void reinitBug()
{
KeyParameter key = new KeyParameter(Hex.decode("80000000000000000000000000000000"));
ParametersWithIV parameters = new ParametersWithIV(key, Hex.decode("0000000000000000"));
StreamCipher salsa = new ChaChaEngine();
salsa.init(true, parameters);
try
{
salsa.init(true, key);
fail("Salsa20 should throw exception if no IV in Init");
}
catch (IllegalArgumentException e)
{
}
}
示例4: Grain128Test1
import org.bouncycastle.crypto.StreamCipher; //导入依赖的package包/类
private void Grain128Test1(CipherParameters params)
{
StreamCipher grain = new Grain128Engine();
byte[] in = new byte[16];
byte[] out = new byte[16];
grain.init(true, params);
grain.processBytes(in, 0, in.length, out, 0);
if (!areEqual(out, Hex.decode(keyStream1)))
{
mismatch("Keystream 1", keyStream1, out);
}
grain.reset();
grain.processBytes(in, 0, in.length, out, 0);
if (!areEqual(out, Hex.decode(keyStream1)))
{
mismatch("Keystream 1", keyStream1, out);
}
}
示例5: Grain128Test2
import org.bouncycastle.crypto.StreamCipher; //导入依赖的package包/类
private void Grain128Test2(CipherParameters params)
{
StreamCipher grain = new Grain128Engine();
byte[] in = new byte[16];
byte[] out = new byte[16];
grain.init(true, params);
grain.processBytes(in, 0, in.length, out, 0);
if (!areEqual(out, Hex.decode(keyStream2)))
{
mismatch("Keystream 2", keyStream2, out);
}
grain.reset();
grain.processBytes(in, 0, in.length, out, 0);
if (!areEqual(out, Hex.decode(keyStream2)))
{
mismatch("Keystream 2", keyStream2, out);
}
}
示例6: Grain128Test3
import org.bouncycastle.crypto.StreamCipher; //导入依赖的package包/类
private void Grain128Test3(CipherParameters params)
{
StreamCipher grain = new Grain128Engine();
byte[] in = "Encrypt me!".getBytes();
byte[] cipher = new byte[in.length];
byte[] clear = new byte[in.length];
grain.init(true, params);
grain.processBytes(in, 0, in.length, cipher, 0);
grain.reset();
grain.processBytes(cipher, 0, cipher.length, clear, 0);
if (!areEqual(in, clear))
{
mismatch("Test 3", new String(Hex.encode(in)), clear);
}
}
示例7: createCipherInputStream
import org.bouncycastle.crypto.StreamCipher; //导入依赖的package包/类
private InputStream createCipherInputStream(byte[] data, Object cipher)
{
ByteArrayInputStream input = new ByteArrayInputStream(data);
if (cipher instanceof BufferedBlockCipher)
{
return new CipherInputStream(input, (BufferedBlockCipher)cipher);
}
else if (cipher instanceof AEADBlockCipher)
{
return new CipherInputStream(input, (AEADBlockCipher)cipher);
}
else
{
return new CipherInputStream(input, (StreamCipher)cipher);
}
}
示例8: getName
import org.bouncycastle.crypto.StreamCipher; //导入依赖的package包/类
private String getName(Object cipher)
{
if (cipher instanceof BufferedBlockCipher)
{
return ((BufferedBlockCipher)cipher).getUnderlyingCipher().getAlgorithmName();
}
else if (cipher instanceof AEADBlockCipher)
{
return ((AEADBlockCipher)cipher).getUnderlyingCipher().getAlgorithmName();
}
else if (cipher instanceof StreamCipher)
{
return ((StreamCipher)cipher).getAlgorithmName();
}
return null;
}
示例9: getBlockSize
import org.bouncycastle.crypto.StreamCipher; //导入依赖的package包/类
private int getBlockSize(Object cipher)
{
if (cipher instanceof BlockCipher)
{
return ((BlockCipher)cipher).getBlockSize();
}
else if (cipher instanceof BufferedBlockCipher)
{
return ((BufferedBlockCipher)cipher).getBlockSize();
}
else if (cipher instanceof AEADBlockCipher)
{
return ((AEADBlockCipher)cipher).getUnderlyingCipher().getBlockSize();
}
else if (cipher instanceof StreamCipher)
{
return 1;
}
return 0;
}
示例10: Grainv1Test1
import org.bouncycastle.crypto.StreamCipher; //导入依赖的package包/类
private void Grainv1Test1(CipherParameters params)
{
StreamCipher grain = new Grainv1Engine();
byte[] in = new byte[10];
byte[] out = new byte[10];
grain.init(true, params);
grain.processBytes(in, 0, in.length, out, 0);
if (!areEqual(out, Hex.decode(keyStream1)))
{
mismatch("Keystream 1", keyStream1, out);
}
grain.reset();
grain.processBytes(in, 0, in.length, out, 0);
if (!areEqual(out, Hex.decode(keyStream1)))
{
mismatch("Keystream 1", keyStream1, out);
}
}
示例11: Grainv1Test2
import org.bouncycastle.crypto.StreamCipher; //导入依赖的package包/类
private void Grainv1Test2(CipherParameters params)
{
StreamCipher grain = new Grainv1Engine();
byte[] in = new byte[10];
byte[] out = new byte[10];
grain.init(true, params);
grain.processBytes(in, 0, in.length, out, 0);
if (!areEqual(out, Hex.decode(keyStream2)))
{
mismatch("Keystream 2", keyStream2, out);
}
grain.reset();
grain.processBytes(in, 0, in.length, out, 0);
if (!areEqual(out, Hex.decode(keyStream2)))
{
mismatch("Keystream 2", keyStream2, out);
}
}
示例12: Grainv1Test3
import org.bouncycastle.crypto.StreamCipher; //导入依赖的package包/类
private void Grainv1Test3(CipherParameters params)
{
StreamCipher grain = new Grainv1Engine();
byte[] in = "Encrypt me!".getBytes();
byte[] cipher = new byte[in.length];
byte[] clear = new byte[in.length];
grain.init(true, params);
grain.processBytes(in, 0, in.length, cipher, 0);
grain.reset();
grain.processBytes(cipher, 0, cipher.length, clear, 0);
if (!areEqual(in, clear))
{
mismatch("Test 3", new String(Hex.encode(in)), clear);
}
}
示例13: reinitBug
import org.bouncycastle.crypto.StreamCipher; //导入依赖的package包/类
private void reinitBug()
{
KeyParameter key = new KeyParameter(Hex.decode("80000000000000000000000000000000"));
ParametersWithIV parameters = new ParametersWithIV(key, Hex.decode("0000000000000000"));
StreamCipher salsa = new Salsa20Engine();
salsa.init(true, parameters);
try
{
salsa.init(true, key);
fail("Salsa20 should throw exception if no IV in Init");
}
catch (IllegalArgumentException e)
{
}
}
示例14: testReset
import org.bouncycastle.crypto.StreamCipher; //导入依赖的package包/类
private void testReset(StreamCipher cipher1, StreamCipher cipher2, CipherParameters params)
throws InvalidCipherTextException
{
cipher1.init(true, params);
byte[] plaintext = new byte[1023];
byte[] ciphertext = new byte[plaintext.length];
// Establish baseline answer
cipher1.processBytes(plaintext, 0, plaintext.length, ciphertext, 0);
// Test encryption resets
checkReset(cipher1, params, true, plaintext, ciphertext);
// Test decryption resets with fresh instance
cipher2.init(false, params);
checkReset(cipher2, params, false, ciphertext, plaintext);
}
示例15: CipherContext
import org.bouncycastle.crypto.StreamCipher; //导入依赖的package包/类
/**
* Class constructor
*
* @param cipherMechanism block cipher mechanism identifier
* @param paddingMechanism padding mechanism identifier
* @param streamCipher stream cipher object
* @param key destroyable key
* @param iv initial vector
*/
public CipherContext(final TypesProto.CipherMechanism cipherMechanism,
final TypesProto.PaddingMechanism paddingMechanism,
final StreamCipher streamCipher,
final DestroyableKey key,
final byte[] iv) {
if (Objects.isNull(cipherMechanism)) {
throw new IllegalArgumentException("cipher mechanism is null");
} else if (Objects.isNull(streamCipher)) {
throw new IllegalArgumentException("blockCipher is null");
} else if (Objects.isNull(key)) {
throw new IllegalArgumentException("key is null");
}else if (Objects.isNull(iv)) {
throw new IllegalArgumentException("iv is null");
}
this.cipherMechanism = cipherMechanism;
this.paddingMechanism = paddingMechanism;
this.streamCipher = streamCipher;
this.key = key;
this.iv = iv;
this.blockCipher = null;
this.padding = null;
}