當前位置: 首頁>>代碼示例>>Java>>正文


Java DHPublicKey.getEncoded方法代碼示例

本文整理匯總了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);
}
 
開發者ID:SlientWizard,項目名稱:Zen-of-Affair,代碼行數:15,代碼來源:SymmetricKeyGenerator.java

示例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();
}
 
開發者ID:SlientWizard,項目名稱:Zen-of-Affair,代碼行數:12,代碼來源:DHKeyGenerator.java

示例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();
}
 
開發者ID:laidu,項目名稱:java-learn,代碼行數:8,代碼來源:DHUtil.java


注:本文中的javax.crypto.interfaces.DHPublicKey.getEncoded方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。