本文整理汇总了Java中javax.crypto.interfaces.DHPublicKey.getEncoded方法的典型用法代码示例。如果您正苦于以下问题:Java DHPublicKey.getEncoded方法的具体用法?Java DHPublicKey.getEncoded怎么用?Java DHPublicKey.getEncoded使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.crypto.interfaces.DHPublicKey
的用法示例。
在下文中一共展示了DHPublicKey.getEncoded方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SymmetricKeyGenerator
import javax.crypto.interfaces.DHPublicKey; //导入方法依赖的package包/类
public SymmetricKeyGenerator(DHPublicKey pubKey, DHPrivateKey priKey) throws Exception
{
byte[] publicKey = pubKey.getEncoded();
byte[] privateKey = priKey.getEncoded();
java.security.KeyFactory keyFactory = KeyFactory.getInstance("DH");
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(publicKey);
PublicKey pubKey1 = keyFactory.generatePublic(x509KeySpec);
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(privateKey);
PrivateKey priKey1 = keyFactory.generatePrivate(pkcs8KeySpec);
KeyAgreement keyAgree = KeyAgreement.getInstance(keyFactory.getAlgorithm());
keyAgree.init(priKey1);
keyAgree.doPhase(pubKey1, true);
secretKey = keyAgree.generateSecret(KEY_ALGORITHM);
}
示例2: generateKey
import javax.crypto.interfaces.DHPublicKey; //导入方法依赖的package包/类
public void generateKey(DHPublicKey publicKey) throws Exception
{
byte[] key = publicKey.getEncoded();
X509EncodedKeySpec X509KeySpec = new X509EncodedKeySpec(key);
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
PublicKey pubKey = keyFactory.generatePublic(X509KeySpec);
DHParameterSpec dhParameterSpec = ((DHPublicKey)pubKey).getParams();
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_ALGORITHM);
keyPairGenerator.initialize(KEY_SIZE);
keyPair = keyPairGenerator.generateKeyPair();
}
示例3: getPublicKey
import javax.crypto.interfaces.DHPublicKey; //导入方法依赖的package包/类
/**
* 从Map中取得公钥
*/
public static byte[] getPublicKey(Map<String, Object> keyMap){
DHPublicKey key = (DHPublicKey) keyMap.get(PUBLIC_KEY);
return key.getEncoded();
}