本文整理汇总了Java中org.spongycastle.crypto.params.IESWithCipherParameters类的典型用法代码示例。如果您正苦于以下问题:Java IESWithCipherParameters类的具体用法?Java IESWithCipherParameters怎么用?Java IESWithCipherParameters使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IESWithCipherParameters类属于org.spongycastle.crypto.params包,在下文中一共展示了IESWithCipherParameters类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCipherParameters
import org.spongycastle.crypto.params.IESWithCipherParameters; //导入依赖的package包/类
private CipherParameters getCipherParameters() {
return new IESWithCipherParameters(null, null, MAC_KEY_BITS,
CIPHER_KEY_BITS);
}
示例2: encryptBlock
import org.spongycastle.crypto.params.IESWithCipherParameters; //导入依赖的package包/类
private byte[] encryptBlock(byte[] in, int inOff, int inLen) throws InvalidCipherTextException {
byte[] C = null, K = null, K1 = null, K2 = null;
int len;
if (cipher == null) {
// Streaming mode.
K1 = new byte[inLen];
K2 = new byte[param.getMacKeySize() / 8];
K = new byte[K1.length + K2.length];
kdf.generateBytes(K, 0, K.length);
if (V.length != 0) {
System.arraycopy(K, 0, K2, 0, K2.length);
System.arraycopy(K, K2.length, K1, 0, K1.length);
} else {
System.arraycopy(K, 0, K1, 0, K1.length);
System.arraycopy(K, inLen, K2, 0, K2.length);
}
C = new byte[inLen];
for (int i = 0; i != inLen; i++) {
C[i] = (byte) (in[inOff + i] ^ K1[i]);
}
len = inLen;
} else {
// Block cipher mode.
K1 = new byte[((IESWithCipherParameters) param).getCipherKeySize() / 8];
K2 = new byte[param.getMacKeySize() / 8];
K = new byte[K1.length + K2.length];
kdf.generateBytes(K, 0, K.length);
System.arraycopy(K, 0, K1, 0, K1.length);
System.arraycopy(K, K1.length, K2, 0, K2.length);
// If iv provided use it to initialise the cipher
if (IV != null) {
cipher.init(true, new ParametersWithIV(new KeyParameter(K1), IV));
} else {
cipher.init(true, new KeyParameter(K1));
}
C = new byte[cipher.getOutputSize(inLen)];
len = cipher.processBytes(in, inOff, inLen, C, 0);
len += cipher.doFinal(C, len);
}
// Convert the length of the encoding vector into a byte array.
byte[] P2 = param.getEncodingV();
byte[] L2 = new byte[4];
if (V.length != 0 && P2 != null) {
Pack.intToBigEndian(P2.length * 8, L2, 0);
}
// Apply the MAC.
byte[] T = new byte[mac.getMacSize()];
byte[] K2a = new byte[hash.getDigestSize()];
hash.reset();
hash.update(K2, 0, K2.length);
hash.doFinal(K2a, 0);
mac.init(new KeyParameter(K2a));
mac.update(IV, 0, IV.length);
mac.update(C, 0, C.length);
if (P2 != null) {
mac.update(P2, 0, P2.length);
}
if (V.length != 0) {
mac.update(L2, 0, L2.length);
}
mac.doFinal(T, 0);
// Output the triple (V,C,T).
byte[] Output = new byte[V.length + len + T.length];
System.arraycopy(V, 0, Output, 0, V.length);
System.arraycopy(C, 0, Output, V.length, len);
System.arraycopy(T, 0, Output, V.length + len, T.length);
return Output;
}