本文整理汇总了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();
}
}
示例2: getFrameCipher
import org.spongycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
public AuthenticatedCipher getFrameCipher() {
AEADBlockCipher a = new GCMBlockCipher(new AESLightEngine());
return new AuthenticatedCipherImpl(a, MAC_BYTES);
}
示例3: AuthenticatedCipherImpl
import org.spongycastle.crypto.modes.AEADBlockCipher; //导入依赖的package包/类
AuthenticatedCipherImpl(AEADBlockCipher cipher, int macLength) {
this.cipher = cipher;
this.macLength = macLength;
}