本文整理汇总了Java中org.bouncycastle.crypto.modes.AEADBlockCipher.processBytes方法的典型用法代码示例。如果您正苦于以下问题:Java AEADBlockCipher.processBytes方法的具体用法?Java AEADBlockCipher.processBytes怎么用?Java AEADBlockCipher.processBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.modes.AEADBlockCipher
的用法示例。
在下文中一共展示了AEADBlockCipher.processBytes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateCiphers
import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入方法依赖的package包/类
private int updateCiphers(AEADBlockCipher c1, AEADBlockCipher c2, byte[] S, int i,
boolean includeAAD, boolean includePlaintext)
throws InvalidCipherTextException
{
int inputLen = includePlaintext ? i : 0;
int outputLen = c2.getOutputSize(inputLen);
byte[] output = new byte[outputLen];
int len = 0;
if (includeAAD)
{
c2.processAADBytes(S, 0, i);
}
if (includePlaintext)
{
len += c2.processBytes(S, 0, i, output, len);
}
len += c2.doFinal(output, len);
c1.processAADBytes(output, 0, len);
return len;
}
示例2: updateCiphers
import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入方法依赖的package包/类
private int updateCiphers(AEADBlockCipher c1, AEADBlockCipher c2, byte[] S, int i,
boolean includeAAD, boolean includePlaintext)
throws InvalidCipherTextException
{
int inputLen = includePlaintext ? i : 0;
int outputLen = c2.getOutputSize(inputLen);
byte[] output = new byte[outputLen];
int len = 0;
if (includeAAD)
{
c2.processAADBytes(S, 0, i);
}
if (includePlaintext)
{
len += c2.processBytes(S, 0, i, output, len);
}
len += c2.doFinal(output, len);
c1.processAADBytes(output, 0, len);
return len;
}
示例3: cipherData
import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入方法依赖的package包/类
private static byte[] cipherData(AEADBlockCipher cipher, byte[] data) throws IllegalStateException, InvalidCipherTextException {
int minSize = cipher.getOutputSize(data.length);
byte[] outBuf = new byte[minSize];
int length1 = cipher.processBytes(data, 0, data.length, outBuf, 0);
int length2 = cipher.doFinal(outBuf, length1);
int actualLength = length1 + length2;
if (actualLength == minSize) {
return outBuf;
} else {
return Arrays.copyOf(outBuf, actualLength);
}
}
示例4: crypt
import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入方法依赖的package包/类
private static void crypt(AEADBlockCipher cipher, byte[] plaintext, byte[] output)
throws InvalidCipherTextException
{
int len = cipher.processBytes(plaintext, 0, plaintext.length, output, 0);
cipher.doFinal(output, len);
}
示例5: testEncryptionWithBCLowLevelAPI
import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入方法依赖的package包/类
@Test
public void testEncryptionWithBCLowLevelAPI() throws Exception
{
final byte[] plain = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
final byte[] key = new byte[] {
1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32
};
final byte[] iv = new byte[] {
1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16
};
// { // first try CFB - works fine, currently (2011-09-23).
// CipherParameters parameters = new ParametersWithIV(new KeyParameter(key), iv);
// byte[] firstCiphertext = null;
// BufferedBlockCipher cipher = new BufferedBlockCipher(new CFBBlockCipher(new TwofishEngine(), 128));
//
// cipher.init(true, parameters);
//
// for (int i = 0; i < 10000; ++i) {
// System.out.println("*** cfb " + i + " ***");
//
// // Whether we re-initialise with or without key does not matter.
// cipher.init(true, parameters);
//
// byte[] ciphertext = new byte[cipher.getOutputSize(plain.length)];
// int encLength = cipher.processBytes(plain, 0, plain.length, ciphertext, 0);
// cipher.doFinal(ciphertext, encLength);
//
// if (firstCiphertext == null)
// firstCiphertext = ciphertext;
// else
// Assert.assertArrayEquals(firstCiphertext, ciphertext);
// }
// }
{ // now try GCM - fails on 'fhernhache', currently (2011-09-23).
byte[] firstCiphertext = null;
// AEADParameters parameters = new AEADParameters(new KeyParameter(key), 128, iv, plain);
final AEADBlockCipher cipher = new GCMBlockCipher(new TwofishEngine());
final AEADBlockCipher invCipher = new GCMBlockCipher(new TwofishEngine());
cipher.init(true, new ParametersWithIV(new KeyParameter(key), iv));
invCipher.init(false, new ParametersWithIV(new KeyParameter(key), iv));
for (int i = 0; i < 10000; ++i) {
System.out.println("*** gcm " + i + " ***");
random.nextBytes(iv);
// Whether we re-initialise with or without key does not matter.
cipher.init(true, new ParametersWithIV(null, iv));
invCipher.init(false, new ParametersWithIV(null, iv));
final byte[] ciphertext = new byte[cipher.getOutputSize(plain.length)];
final int encLength = cipher.processBytes(plain, 0, plain.length, ciphertext, 0);
cipher.doFinal(ciphertext, encLength);
if (firstCiphertext == null)
firstCiphertext = ciphertext;
else
assertThat(ciphertext).isNotEqualTo(firstCiphertext);
final byte[] decrypted = new byte[cipher.getOutputSize(ciphertext.length)];
int decLength = invCipher.processBytes(ciphertext, 0, ciphertext.length, decrypted, 0);
decLength += invCipher.doFinal(decrypted, decLength);
final byte[] decryptedTruncated = new byte[decLength];
System.arraycopy(decrypted, 0, decryptedTruncated, 0, decLength);
assertThat(decryptedTruncated).isEqualTo(plain);
}
}
}
示例6: ivParamTest
import org.bouncycastle.crypto.modes.AEADBlockCipher; //导入方法依赖的package包/类
private void ivParamTest(
int count,
AEADBlockCipher eax,
byte[] k,
byte[] n)
throws InvalidCipherTextException
{
byte[] p = Strings.toByteArray("hello world!!");
eax.init(true, new ParametersWithIV(new KeyParameter(k), n));
byte[] enc = new byte[p.length + 8];
int len = eax.processBytes(p, 0, p.length, enc, 0);
len += eax.doFinal(enc, len);
eax.init(false, new ParametersWithIV(new KeyParameter(k), n));
byte[] tmp = new byte[enc.length];
len = eax.processBytes(enc, 0, enc.length, tmp, 0);
len += eax.doFinal(tmp, len);
byte[] dec = new byte[len];
System.arraycopy(tmp, 0, dec, 0, len);
if (!areEqual(p, dec))
{
fail("decrypted stream fails to match in test " + count);
}
}