本文整理汇总了Java中org.bouncycastle.crypto.params.IESWithCipherParameters类的典型用法代码示例。如果您正苦于以下问题:Java IESWithCipherParameters类的具体用法?Java IESWithCipherParameters怎么用?Java IESWithCipherParameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IESWithCipherParameters类属于org.bouncycastle.crypto.params包,在下文中一共展示了IESWithCipherParameters类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: decryptMessage
import org.bouncycastle.crypto.params.IESWithCipherParameters; //导入依赖的package包/类
public static byte[] decryptMessage(PrivateKey key, ECIESMessage message) throws ECIESException {
try {
// check key algorithm
if (!key.getAlgorithm().equals(ASYMMETRIC_ALGORITHM))
throw new ECIESException("Wrong key algorithm");
// IES engine
IESEngine ies = getIESEngine();
// initialize engine
Curve25519DecryptionParameter ep = new Curve25519DecryptionParameter(key.getEncoded(), message.getR());
ParametersWithIV p = new ParametersWithIV(new IESWithCipherParameters(message.getSh1(), message.getSh2(), MAC_KEY_SIZE_BITS, AES_KEY_SIZE_BITS), message.getIv());
ies.init(false, null, ep, p);
// decrypt and return data
return ies.processBlock(message.getCd(), 0, message.getCd().length);
} catch (InvalidCipherTextException ex) {
throw new ECIESException("Message corrupted or wrong key", ex);
}
}
开发者ID:Gherynos,项目名称:secrete,代码行数:25,代码来源:ECIES.java
示例2: encryptData
import org.bouncycastle.crypto.params.IESWithCipherParameters; //导入依赖的package包/类
private static ECIESMessage encryptData(PublicKey key, byte[] data, boolean binary, SecureRandom random) throws ECIESException {
try {
// check key algorithm
if (!key.getAlgorithm().equals(ASYMMETRIC_ALGORITHM))
throw new ECIESException("Wrong key algorithm");
// generate shared information
byte[] sh1 = new byte[SHARED_INFORMATION_SIZE_BYTES];
random.nextBytes(sh1);
byte[] sh2 = new byte[SHARED_INFORMATION_SIZE_BYTES];
random.nextBytes(sh2);
byte[] iv = new byte[IV_SIZE_BYTES];
random.nextBytes(iv);
// generate R
byte[] r = new byte[Curve25519.KEY_SIZE];
random.nextBytes(r);
byte[] R = new byte[Curve25519.KEY_SIZE];
Curve25519.curve(R, r, null);
// IES engine
IESEngine ies = getIESEngine();
// initialize engine
Curve25519EncryptionParameter ep = new Curve25519EncryptionParameter(key.getEncoded(), r);
ParametersWithIV p = new ParametersWithIV(new IESWithCipherParameters(sh1, sh2, MAC_KEY_SIZE_BITS, AES_KEY_SIZE_BITS), iv);
ies.init(true, null, ep, p);
// encrypt data
byte[] cd = ies.processBlock(data, 0, data.length);
// return message
return new ECIESMessage(sh1, sh2, iv, R, cd, binary);
} catch (InvalidCipherTextException ex) {
throw new ECIESException("Message corrupted or wrong key", ex);
}
}
开发者ID:Gherynos,项目名称:secrete,代码行数:42,代码来源:ECIES.java
注:本文中的org.bouncycastle.crypto.params.IESWithCipherParameters类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论