本文整理匯總了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();
}