当前位置: 首页>>代码示例>>Java>>正文


Java EAXBlockCipher.getOutputSize方法代码示例

本文整理汇总了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");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:36,代码来源:EAXTest.java

示例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);
	}
}
 
开发者ID:andy-goryachev,项目名称:PasswordSafe,代码行数:30,代码来源:MemCrypt.java

示例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);
	}
}
 
开发者ID:andy-goryachev,项目名称:PasswordSafe,代码行数:28,代码来源:MemCrypt.java


注:本文中的org.bouncycastle.crypto.modes.EAXBlockCipher.getOutputSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。