本文整理汇总了Java中org.bouncycastle.crypto.agreement.ECDHBasicAgreement类的典型用法代码示例。如果您正苦于以下问题:Java ECDHBasicAgreement类的具体用法?Java ECDHBasicAgreement怎么用?Java ECDHBasicAgreement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ECDHBasicAgreement类属于org.bouncycastle.crypto.agreement包,在下文中一共展示了ECDHBasicAgreement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateSharedSecret
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
/**
* Generate a shared AES key using ECDH.
*/
public static byte[] generateSharedSecret(byte[] privateKey, byte[] publicKey) {
try {
ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(SECP256K1);
ECDomainParameters domain =
new ECDomainParameters(spec.getCurve(), spec.getG(), spec.getN(), spec.getH());
ECPublicKeyParameters pubKey =
new ECPublicKeyParameters(spec.getCurve().decodePoint(publicKey), domain);
ECPrivateKeyParameters prvkey =
new ECPrivateKeyParameters(new BigInteger(1, privateKey), domain);
ECDHBasicAgreement agreement = new ECDHBasicAgreement();
agreement.init(prvkey);
byte[] password = agreement.calculateAgreement(pubKey).toByteArray();
return Aes.generateKey(ByteUtilities.toHexString(password), password);
} catch (Exception e) {
LOGGER.error(null, e);
return new byte[0];
}
}
示例2: curveTest
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
@Test
public void curveTest() {
final X9ECParameters curve = NISTNamedCurves.getByName("P-384");
final ECDomainParameters domainParameters = new ECDomainParameters(
curve.getCurve(), curve.getG(), curve.getN());
final SecureRandom random = new SecureRandom();
final ECKeyPairGenerator gen = new ECKeyPairGenerator();
gen.init(new ECKeyGenerationParameters(domainParameters, random));
final AsymmetricCipherKeyPair senderPair = gen.generateKeyPair();
final AsymmetricCipherKeyPair receiverPair = gen.generateKeyPair();
final ECDHBasicAgreement senderAgreement = new ECDHBasicAgreement();
senderAgreement.init(senderPair.getPrivate());
final BigInteger senderResult = senderAgreement.calculateAgreement(
receiverPair.getPublic());
final ECDHBasicAgreement receiverAgreement = new ECDHBasicAgreement();
receiverAgreement.init(receiverPair.getPrivate());
final BigInteger receiverResult = receiverAgreement.calculateAgreement(
senderPair.getPublic());
assertEquals(senderResult, receiverResult);
//System.out.println(receiverResult);
}
示例3: calculateECDHBasicAgreement
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public static byte[] calculateECDHBasicAgreement(ECPublicKeyParameters publicKey, ECPrivateKeyParameters privateKey)
{
ECDHBasicAgreement basicAgreement = new ECDHBasicAgreement();
basicAgreement.init(privateKey);
BigInteger agreementValue = basicAgreement.calculateAgreement(publicKey);
/*
* RFC 4492 5.10. Note that this octet string (Z in IEEE 1363 terminology) as output by
* FE2OSP, the Field Element to Octet String Conversion Primitive, has constant length for
* any given field; leading zeros found in this octet string MUST NOT be truncated.
*/
return BigIntegers.asUnsignedByteArray(basicAgreement.getFieldSize(), agreementValue);
}
示例4: ECIESwithDESede
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public ECIESwithDESede()
{
super(new IESEngine(new ECDHBasicAgreement(),
new KDF2BytesGenerator(new SHA1Digest()),
new HMac(new SHA1Digest()),
new PaddedBufferedBlockCipher(new DESedeEngine())));
}
示例5: ECIESwithAES
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public ECIESwithAES()
{
super(new IESEngine(new ECDHBasicAgreement(),
new KDF2BytesGenerator(new SHA1Digest()),
new HMac(new SHA1Digest()),
new PaddedBufferedBlockCipher(new AESEngine())));
}
示例6: ECIES
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public ECIES()
{
super(new IESEngine(
new ECDHBasicAgreement(),
new KDF2BytesGenerator(new SHA1Digest()),
new HMac(new SHA1Digest())));
}
示例7: calculateECDHBasicAgreement
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public static byte[] calculateECDHBasicAgreement(ECPublicKeyParameters publicKey, ECPrivateKeyParameters privateKey)
{
ECDHBasicAgreement basicAgreement = new ECDHBasicAgreement();
basicAgreement.init(privateKey);
BigInteger agreementValue = basicAgreement.calculateAgreement(publicKey);
/*
* RFC 4492 5.10. Note that this octet string (Z in IEEE 1363 terminology) as output by
* FE2OSP, the Field Element to Octet String Conversion Primitive, has constant length for
* any given field; leading zeros found in this octet string MUST NOT be truncated.
*/
return BigIntegers.asUnsignedByteArray(basicAgreement.getFieldSize(), agreementValue);
}
示例8: main
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public static void main( String[] args ) throws InvalidKeySpecException, InvalidKeyException, IOException {
ECPublicKey clientKey = (ECPublicKey) ECDH_KEY_FACTORY.generatePublic( new X509EncodedKeySpec( Base64.getDecoder().decode( "MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEDEKneqEvcqUqqFMM1HM1A4zWjJC+I8Y+aKzG5dl+6wNOHHQ4NmG2PEXRJYhujyodFH+wO0dEr4GM1WoaWog8xsYQ6mQJAC0eVpBM96spUB1eMN56+BwlJ4H3Qx4TAvAs" ) ) );
ECPrivateKey privateKey = (ECPrivateKey) ECDH_KEY_FACTORY.generatePrivate( new PKCS8EncodedKeySpec( Base64.getDecoder().decode( "MB8CAQAwEAYHKoZIzj0CAQYFK4EEACIECDAGAgEBBAEB" ) ) );
ECDHBasicAgreement agreement = new ECDHBasicAgreement();
agreement.init( PrivateKeyFactory.createKey( privateKey.getEncoded() ) );
byte[] secret = agreement.calculateAgreement( PublicKeyFactory.createKey( clientKey.getEncoded() ) ).toByteArray();
System.out.println( Util.toHexString( secret ) );
System.out.println( Util.toHexString( Base64.getDecoder().decode( "DEKneqEvcqUqqFMM1HM1A4zWjJC+I8Y+aKzG5dl+6wNOHHQ4NmG2PEXRJYhujyod" ) ) );
}
示例9: ECIESwithCipher
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public ECIESwithCipher(BlockCipher cipher)
{
super(new IESEngine(new ECDHBasicAgreement(),
new KDF2BytesGenerator(new SHA1Digest()),
new HMac(new SHA1Digest()),
new PaddedBufferedBlockCipher(cipher)));
}
示例10: OldECIESwithCipher
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public OldECIESwithCipher(BlockCipher baseCipher)
{
super(new OldIESEngine(new ECDHBasicAgreement(),
new KDF2BytesGenerator(new SHA1Digest()),
new HMac(new SHA1Digest()),
new PaddedBufferedBlockCipher(baseCipher)));
}
示例11: sessionKey
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public static AesKey sessionKey(
final CipherParameters receiverKey,
final CipherParameters senderKey,
final CipherParameters privateKey,
final ECPublicKeyParameters publicKey
) {
final ECDHBasicAgreement senderAgreement = new ECDHBasicAgreement();
senderAgreement.init(privateKey);
final EcdhSharedSecret sharedSecret = new EcdhSharedSecret(
((ECPublicKeyParameters)receiverKey).getQ(),
((ECPublicKeyParameters)senderKey).getQ(),
senderAgreement.calculateAgreement(publicKey));
final DigestSha384 hash = DigestSha384.digest(sharedSecret);
return new AesKey(Arrays.copyOf(hash.getBytes(), AesKey.AES_KEY_BYTES));
}
示例12: DH
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public DH()
{
super("ECDH", new ECDHBasicAgreement(), null);
}
示例13: DHwithSHA1KDF
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public DHwithSHA1KDF()
{
super("ECDHwithSHA1KDF", new ECDHBasicAgreement(), new ECDHKEKGenerator(new SHA1Digest()));
}
示例14: ECIES
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public ECIES()
{
super(new IESEngine(new ECDHBasicAgreement(),
new KDF2BytesGenerator(new SHA1Digest()),
new HMac(new SHA1Digest())));
}
示例15: DH
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; //导入依赖的package包/类
public DH()
{
super(new ECDHBasicAgreement());
}