本文整理汇总了Java中org.bouncycastle.crypto.modes.EAXBlockCipher.doFinal方法的典型用法代码示例。如果您正苦于以下问题:Java EAXBlockCipher.doFinal方法的具体用法?Java EAXBlockCipher.doFinal怎么用?Java EAXBlockCipher.doFinal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.modes.EAXBlockCipher
的用法示例。
在下文中一共展示了EAXBlockCipher.doFinal方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doEax
import org.bouncycastle.crypto.modes.EAXBlockCipher; //导入方法依赖的package包/类
private void doEax(byte[] key, byte[] iv, byte[] pt, byte[] aad, int tagLength, byte[] expected)
throws InvalidCipherTextException
{
EAXBlockCipher c = new EAXBlockCipher(new SerpentEngine());
c.init(true, new AEADParameters(new KeyParameter(key), tagLength, iv, aad));
byte[] out = new byte[expected.length];
int len = c.processBytes(pt, 0, pt.length, out, 0);
c.doFinal(out, len);
if (!Arrays.areEqual(expected, out))
{
fail("EAX test failed");
}
}
示例2: randomTest
import org.bouncycastle.crypto.modes.EAXBlockCipher; //导入方法依赖的package包/类
private void randomTest(
SecureRandom srng)
throws InvalidCipherTextException
{
int DAT_LEN = srng.nextInt() >>> 22; // Note: JDK1.0 compatibility
byte[] nonce = new byte[NONCE_LEN];
byte[] authen = new byte[AUTHEN_LEN];
byte[] datIn = new byte[DAT_LEN];
byte[] key = new byte[16];
srng.nextBytes(nonce);
srng.nextBytes(authen);
srng.nextBytes(datIn);
srng.nextBytes(key);
AESFastEngine engine = new AESFastEngine();
KeyParameter sessKey = new KeyParameter(key);
EAXBlockCipher eaxCipher = new EAXBlockCipher(engine);
AEADParameters params = new AEADParameters(sessKey, MAC_LEN * 8, nonce, authen);
eaxCipher.init(true, params);
byte[] intrDat = new byte[eaxCipher.getOutputSize(datIn.length)];
int outOff = eaxCipher.processBytes(datIn, 0, DAT_LEN, intrDat, 0);
outOff += eaxCipher.doFinal(intrDat, outOff);
eaxCipher.init(false, params);
byte[] datOut = new byte[eaxCipher.getOutputSize(outOff)];
int resultLen = eaxCipher.processBytes(intrDat, 0, outOff, datOut, 0);
eaxCipher.doFinal(datOut, resultLen);
if (!areEqual(datIn, datOut))
{
fail("EAX roundtrip failed to match");
}
}
示例3: encrypt
import org.bouncycastle.crypto.modes.EAXBlockCipher; //导入方法依赖的package包/类
public static final byte[] encrypt(byte[] data) throws Exception
{
EAXBlockCipher cipher = new EAXBlockCipher(new AESEngine());
byte[] nonce = new byte[NONCE_SIZE_BYTES];
new SecureRandom().nextBytes(nonce);
byte[] key = generateKey();
KeyParameter kp = new KeyParameter(key);
try
{
AEADParameters par = new AEADParameters(kp, MAC_SIZE_BITS, nonce, ZERO_BYTE_ARRAY);
cipher.init(true, par);
int sz = cipher.getOutputSize(data.length);
byte[] out = new byte[NONCE_SIZE_BYTES + sz];
System.arraycopy(nonce, 0, out, 0, NONCE_SIZE_BYTES);
int off = NONCE_SIZE_BYTES;
off += cipher.processBytes(data, 0, data.length, out, off);
cipher.doFinal(out, off);
return out;
}
finally
{
Crypto.zero(kp);
Crypto.zero(key);
}
}
示例4: decrypt
import org.bouncycastle.crypto.modes.EAXBlockCipher; //导入方法依赖的package包/类
public static final byte[] decrypt(byte[] data) throws Exception
{
EAXBlockCipher cipher = new EAXBlockCipher(new AESEngine());
byte[] nonce = new byte[NONCE_SIZE_BYTES];
System.arraycopy(data, 0, nonce, 0, NONCE_SIZE_BYTES);
byte[] key = generateKey();
KeyParameter kp = new KeyParameter(key);
try
{
AEADParameters par = new AEADParameters(kp, MAC_SIZE_BITS, nonce, ZERO_BYTE_ARRAY);
cipher.init(false, par);
int sz = cipher.getOutputSize(data.length - NONCE_SIZE_BYTES);
byte[] out = new byte[sz];
int off = cipher.processBytes(data, NONCE_SIZE_BYTES, data.length - NONCE_SIZE_BYTES, out, 0);
cipher.doFinal(out, off);
return out;
}
finally
{
Crypto.zero(kp);
Crypto.zero(key);
}
}
示例5: runCheckVectors
import org.bouncycastle.crypto.modes.EAXBlockCipher; //导入方法依赖的package包/类
private void runCheckVectors(
int count,
EAXBlockCipher encEax,
EAXBlockCipher decEax,
String additionalDataType,
byte[] sa,
byte[] p,
byte[] t,
byte[] c)
throws InvalidCipherTextException
{
byte[] enc = new byte[c.length];
if (sa != null)
{
encEax.processAADBytes(sa, 0, sa.length);
}
int len = encEax.processBytes(p, 0, p.length, enc, 0);
len += encEax.doFinal(enc, len);
if (!areEqual(c, enc))
{
fail("encrypted stream fails to match in test " + count + " with " + additionalDataType);
}
byte[] tmp = new byte[enc.length];
if (sa != null)
{
decEax.processAADBytes(sa, 0, sa.length);
}
len = decEax.processBytes(enc, 0, enc.length, tmp, 0);
len += decEax.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 + " with " + additionalDataType);
}
if (!areEqual(t, decEax.getMac()))
{
fail("MAC fails to match in test " + count + " with " + additionalDataType);
}
}
示例6: runCheckVectors
import org.bouncycastle.crypto.modes.EAXBlockCipher; //导入方法依赖的package包/类
private void runCheckVectors(
int count,
EAXBlockCipher encEax,
EAXBlockCipher decEax,
String additionalDataType,
byte[] sa,
byte[] p,
byte[] t,
byte[] c)
throws InvalidCipherTextException
{
byte[] enc = new byte[c.length];
if (sa != null)
{
encEax.processAADBytes(sa, 0, sa.length);
}
int len = encEax.processBytes(p, 0, p.length, enc, 0);
len += encEax.doFinal(enc, len);
if (!areEqual(c, enc))
{
fail("encrypted stream fails to match in test " + count + " with " + additionalDataType);
}
byte[] tmp = new byte[enc.length];
if (sa != null)
{
decEax.processAADBytes(sa, 0, sa.length);
}
len = decEax.processBytes(enc, 0, enc.length, tmp, 0);
len += decEax.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 + " with " + additionalDataType);
}
if (!areEqual(t, decEax.getMac()))
{
fail("MAC fails to match in test " + count + " with " + additionalDataType);
}
}