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


Java AEADBlockCipher类代码示例

本文整理汇总了Java中org.spongycastle.crypto.modes.AEADBlockCipher的典型用法代码示例。如果您正苦于以下问题:Java AEADBlockCipher类的具体用法?Java AEADBlockCipher怎么用?Java AEADBlockCipher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AEADBlockCipher类属于org.spongycastle.crypto.modes包,在下文中一共展示了AEADBlockCipher类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encryptWithPassword

import org.spongycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
public byte[] encryptWithPassword(byte[] input, char[] password) {
	// Generate a random salt
	byte[] salt = new byte[PBKDF_SALT_BYTES];
	secureRandom.nextBytes(salt);
	// Calibrate the KDF
	int iterations = chooseIterationCount(PBKDF_TARGET_MILLIS);
	// Derive the key from the password
	byte[] keyBytes = pbkdf2(password, salt, iterations);
	SecretKey key = new SecretKeyImpl(keyBytes);
	// Generate a random IV
	byte[] iv = new byte[STORAGE_IV_BYTES];
	secureRandom.nextBytes(iv);
	// The output contains the salt, iterations, IV, ciphertext and MAC
	int outputLen = salt.length + 4 + iv.length + input.length + MAC_BYTES;
	byte[] output = new byte[outputLen];
	System.arraycopy(salt, 0, output, 0, salt.length);
	ByteUtils.writeUint32(iterations, output, salt.length);
	System.arraycopy(iv, 0, output, salt.length + 4, iv.length);
	// Initialise the cipher and encrypt the plaintext
	try {
		AEADBlockCipher a = new GCMBlockCipher(new AESLightEngine());
		AuthenticatedCipher cipher = new AuthenticatedCipherImpl(a,
				MAC_BYTES);
		cipher.init(true, key, iv, null);
		int outputOff = salt.length + 4 + iv.length;
		cipher.doFinal(input, 0, input.length, output, outputOff);
		return output;
	} catch(GeneralSecurityException e) {
		throw new RuntimeException(e);
	} finally {
		key.erase();
	}
}
 
开发者ID:kiggundu,项目名称:briar,代码行数:34,代码来源:CryptoComponentImpl.java

示例2: getFrameCipher

import org.spongycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
public AuthenticatedCipher getFrameCipher() {
	AEADBlockCipher a = new GCMBlockCipher(new AESLightEngine());
	return new AuthenticatedCipherImpl(a, MAC_BYTES);
}
 
开发者ID:kiggundu,项目名称:briar,代码行数:5,代码来源:CryptoComponentImpl.java

示例3: AuthenticatedCipherImpl

import org.spongycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
AuthenticatedCipherImpl(AEADBlockCipher cipher, int macLength) {
	this.cipher = cipher;
	this.macLength = macLength;
}
 
开发者ID:kiggundu,项目名称:briar,代码行数:5,代码来源:AuthenticatedCipherImpl.java


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