热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

javax.crypto.KeyAgreement.getInstance()方法的使用及代码示例

本文整理了Java中javax.crypto.KeyAgreement.getInstance()方法的一些代码示例,展示了KeyAgreement.get

本文整理了Java中javax.crypto.KeyAgreement.getInstance()方法的一些代码示例,展示了KeyAgreement.getInstance()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeyAgreement.getInstance()方法的具体详情如下:
包路径:javax.crypto.KeyAgreement
类名称:KeyAgreement
方法名:getInstance

KeyAgreement.getInstance介绍

[英]Creates a new KeyAgreement for the specified algorithm.
[中]为指定的算法创建新的密钥协商。

代码示例

代码示例来源:origin: ethereum/ethereumj

public static KeyAgreement getInstance(final String provider) throws NoSuchProviderException {
try {
return KeyAgreement.getInstance(ALGORITHM, provider);
} catch (NoSuchAlgorithmException ex) {
throw new AssertionError(algorithmAssertionMsg, ex);
}
}

代码示例来源:origin: ethereum/ethereumj

public static KeyAgreement getInstance() {
try {
return KeyAgreement.getInstance(ALGORITHM);
} catch (NoSuchAlgorithmException ex) {
throw new AssertionError(algorithmAssertionMsg, ex);
}
}

代码示例来源:origin: ethereum/ethereumj

public static KeyAgreement getInstance(final Provider provider) {
try {
return KeyAgreement.getInstance(ALGORITHM, provider);
} catch (NoSuchAlgorithmException ex) {
throw new AssertionError(algorithmAssertionMsg, ex);
}
}
}

代码示例来源:origin: hierynomus/sshj

/**
* Creates a new instance of {@link KeyAgreement} with the given algorithm.
*
* @param algorithm key agreement algorithm
* @return new instance
* @throws NoSuchAlgorithmException
* @throws NoSuchProviderException
*/
public static synchronized KeyAgreement getKeyAgreement(String algorithm)
throws NoSuchAlgorithmException, NoSuchProviderException {
register();
if (getSecurityProvider() == null)
return KeyAgreement.getInstance(algorithm);
else
return KeyAgreement.getInstance(algorithm, getSecurityProvider());
}

代码示例来源:origin: robovm/robovm

throw new NoSuchProviderException(provider);
return getInstance(algorithm, impProvider);

代码示例来源:origin: hierynomus/sshj

KeyAgreement.getInstance("DH", provider);
setSecurityProvider(provider.getName());
return true;

代码示例来源:origin: jenkinsci/jenkins

public KeyAgreement diffieHellman(boolean side, int keySize) throws IOException, GeneralSecurityException {
KeyPair keyPair;
PublicKey otherHalf;
if (side) {
AlgorithmParameterGenerator paramGen = AlgorithmParameterGenerator.getInstance("DH");
paramGen.init(keySize);
KeyPairGenerator dh = KeyPairGenerator.getInstance("DH");
dh.initialize(paramGen.generateParameters().getParameterSpec(DHParameterSpec.class));
keyPair = dh.generateKeyPair();
// send a half and get a half
writeKey(keyPair.getPublic());
otherHalf = KeyFactory.getInstance("DH").generatePublic(readKey());
} else {
otherHalf = KeyFactory.getInstance("DH").generatePublic(readKey());
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("DH");
keyPairGen.initialize(((DHPublicKey) otherHalf).getParams());
keyPair = keyPairGen.generateKeyPair();
// send a half and get a half
writeKey(keyPair.getPublic());
}
KeyAgreement ka = KeyAgreement.getInstance("DH");
ka.init(keyPair.getPrivate());
ka.doPhase(otherHalf, true);
return ka;
}

代码示例来源:origin: apache/geode

protected Cipher getEncryptCipher(String dhSKAlgo, PublicKey publicKey) throws Exception {
if (_encrypt == null) {
KeyAgreement ka = KeyAgreement.getInstance("DH");
ka.init(dhPrivateKey);
ka.doPhase(publicKey, true);
Cipher encrypt;
int keysize = getKeySize(dhSKAlgo);
int blocksize = getBlockSize(dhSKAlgo);
if (keysize == -1 || blocksize == -1) {
SecretKey sKey = ka.generateSecret(dhSKAlgo);
encrypt = Cipher.getInstance(dhSKAlgo);
encrypt.init(Cipher.ENCRYPT_MODE, sKey);
} else {
String dhAlgoStr = getDhAlgoStr(dhSKAlgo);
byte[] sKeyBytes = ka.generateSecret();
SecretKeySpec sks = new SecretKeySpec(sKeyBytes, 0, keysize, dhAlgoStr);
IvParameterSpec ivps = new IvParameterSpec(sKeyBytes, keysize, blocksize);
encrypt = Cipher.getInstance(dhAlgoStr + "/CBC/PKCS5Padding");
encrypt.init(Cipher.ENCRYPT_MODE, sks, ivps);
}
_encrypt = encrypt;
}
return _encrypt;
}

代码示例来源:origin: apache/geode

protected Cipher getDecryptCipher(String dhSKAlgo, PublicKey publicKey) throws Exception {
if (_decrypt == null) {
KeyAgreement ka = KeyAgreement.getInstance("DH");
ka.init(dhPrivateKey);
ka.doPhase(publicKey, true);
Cipher decrypt;
int keysize = getKeySize(dhSKAlgo);
int blocksize = getBlockSize(dhSKAlgo);
if (keysize == -1 || blocksize == -1) {
SecretKey sKey = ka.generateSecret(dhSKAlgo);
decrypt = Cipher.getInstance(dhSKAlgo);
decrypt.init(Cipher.DECRYPT_MODE, sKey);
} else {
String algoStr = getDhAlgoStr(dhSKAlgo);
byte[] sKeyBytes = ka.generateSecret();
SecretKeySpec sks = new SecretKeySpec(sKeyBytes, 0, keysize, algoStr);
IvParameterSpec ivps = new IvParameterSpec(sKeyBytes, keysize, blocksize);
decrypt = Cipher.getInstance(algoStr + "/CBC/PKCS5Padding");
decrypt.init(Cipher.DECRYPT_MODE, sks, ivps);
}
_decrypt = decrypt;
}
return _decrypt;
}

代码示例来源:origin: wildfly/wildfly

public void init() throws Exception {
super.init();
if(secret_key_length % 8 != 0)
throw new IllegalStateException(String.format("secret_key_length (%d) must be a multiple of 8", secret_key_length));
ASYM_ENCRYPT asym_encrypt=findProtocolAbove(ASYM_ENCRYPT.class);
if(asym_encrypt != null) {
String sym_alg=asym_encrypt.symAlgorithm();
int sym_keylen=asym_encrypt.symKeylength();
if(Util.match(sym_alg, secret_key_algorithm)) {
log.warn("overriding %s=%s to %s from %s", "secret_key_algorithm", secret_key_algorithm,
sym_alg, ASYM_ENCRYPT.class.getSimpleName());
secret_key_algorithm=sym_alg;
}
if(sym_keylen != secret_key_length) {
log.warn("overriding %s=%d to %d from %s", "secret_key_length", secret_key_length,
sym_keylen, ASYM_ENCRYPT.class.getSimpleName());
secret_key_length=sym_keylen;
}
}
key_agreement=KeyAgreement.getInstance("DH");
}

代码示例来源:origin: apache/geode

private static byte[] generateSecret(String dhSKAlgo, PrivateKey privateKey,
PublicKey otherPublicKey) throws Exception {
KeyAgreement ka = KeyAgreement.getInstance("DH");
ka.init(privateKey);
ka.doPhase(otherPublicKey, true);
int keysize = getKeySize(dhSKAlgo);
int blocksize = getBlockSize(dhSKAlgo);
if (keysize == -1 || blocksize == -1) {
SecretKey sKey = ka.generateSecret(dhSKAlgo);
return sKey.getEncoded();
} else {
return ka.generateSecret();
}
}
}

代码示例来源:origin: apache/geode

KeyAgreement ka = KeyAgreement.getInstance("DH");
ka.init(dhPrivateKey);
ka.doPhase(pubKey, true);

代码示例来源:origin: SeanDragon/protools

KeyAgreement keyAgree = KeyAgreement.getInstance(keyFactory.getAlgorithm());

代码示例来源:origin: ibinti/bugvm

public KeyAgreement createKeyAgreement(String algorithm)
throws NoSuchAlgorithmException
{
return KeyAgreement.getInstance(algorithm, provider);
}

代码示例来源:origin: ibinti/bugvm

public KeyAgreement createKeyAgreement(String algorithm)
throws NoSuchAlgorithmException, NoSuchProviderException
{
return KeyAgreement.getInstance(algorithm, providerName);
}

代码示例来源:origin: nuls-io/nuls

public static KeyAgreement getInstance(final String provider) throws NoSuchProviderException {
try {
return KeyAgreement.getInstance(ALGORITHM, provider);
} catch (NoSuchAlgorithmException ex) {
throw new AssertionError(algorithmAssertionMsg, ex);
}
}

代码示例来源:origin: nuls-io/nuls

public static KeyAgreement getInstance() {
try {
return KeyAgreement.getInstance(ALGORITHM);
} catch (NoSuchAlgorithmException ex) {
throw new AssertionError(algorithmAssertionMsg, ex);
}
}

代码示例来源:origin: nuls-io/nuls

public static KeyAgreement getInstance(final Provider provider) {
try {
return KeyAgreement.getInstance(ALGORITHM, provider);
} catch (NoSuchAlgorithmException ex) {
throw new AssertionError(algorithmAssertionMsg, ex);
}
}
}

代码示例来源:origin: apache/cxf

private static byte[] generateKeyZ(ECPrivateKey privateKey, ECPublicKey publicKey) {
try {
KeyAgreement ka = KeyAgreement.getInstance("ECDH");
ka.init(privateKey);
ka.doPhase(publicKey, true);
return ka.generateSecret();
} catch (Exception ex) {
LOG.warning("Derived key calculation problem");
throw new JweException(JweException.Error.KEY_ENCRYPTION_FAILURE);
}
}
private static byte[] concatenateDatalenAndData(byte[] bytesASCII) {

代码示例来源:origin: RUB-NDS/TLS-Attacker

private void prepareKek(BigInteger priv, PublicKey pub) throws GeneralSecurityException {
KeyAgreement keyAgreement = KeyAgreement.getInstance(getKeyAgreementAlgorithm());
PrivateKey privateKey = generatePrivateKey(priv);
keyAgreement.init(privateKey, new UserKeyingMaterialSpec(msg.getComputations().getUkm().getValue()));
keyAgreement.doPhase(pub, true);
byte[] kek = keyAgreement.generateSecret();
msg.getComputations().setKeyEncryptionKey(kek);
LOGGER.debug("KEK: " + ArrayConverter.bytesToHexString(msg.getComputations().getKeyEncryptionKey()));
}

推荐阅读
author-avatar
阳光因你我而灿烂
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有