本文整理汇总了Java中org.bouncycastle.crypto.modes.EAXBlockCipher.getOutputSize方法的典型用法代码示例。如果您正苦于以下问题:Java EAXBlockCipher.getOutputSize方法的具体用法?Java EAXBlockCipher.getOutputSize怎么用?Java EAXBlockCipher.getOutputSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.modes.EAXBlockCipher
的用法示例。
在下文中一共展示了EAXBlockCipher.getOutputSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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");
}
}
示例2: 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);
}
}
示例3: 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);
}
}