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


Java DHPrivateKey類代碼示例

本文整理匯總了Java中javax.crypto.interfaces.DHPrivateKey的典型用法代碼示例。如果您正苦於以下問題:Java DHPrivateKey類的具體用法?Java DHPrivateKey怎麽用?Java DHPrivateKey使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DHPrivateKey類屬於javax.crypto.interfaces包,在下文中一共展示了DHPrivateKey類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: engineInit

import javax.crypto.interfaces.DHPrivateKey; //導入依賴的package包/類
protected void engineInit(
    Key             key,
    SecureRandom    random) 
    throws InvalidKeyException
{
    if (!(key instanceof DHPrivateKey))
    {
        throw new InvalidKeyException("DHKeyAgreement requires DHPrivateKey");
    }

    DHPrivateKey    privKey = (DHPrivateKey)key;

    this.p = privKey.getParams().getP();
    this.g = privKey.getParams().getG();
    this.x = this.result = privKey.getX();
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:17,代碼來源:KeyAgreementSpi.java

示例2: engineTranslateKey

import javax.crypto.interfaces.DHPrivateKey; //導入依賴的package包/類
protected Key engineTranslateKey(
    Key key)
    throws InvalidKeyException
{
    if (key instanceof DHPublicKey)
    {
        return new BCElGamalPublicKey((DHPublicKey)key);
    }
    else if (key instanceof DHPrivateKey)
    {
        return new BCElGamalPrivateKey((DHPrivateKey)key);
    }
    else if (key instanceof ElGamalPublicKey)
    {
        return new BCElGamalPublicKey((ElGamalPublicKey)key);
    }
    else if (key instanceof ElGamalPrivateKey)
    {
        return new BCElGamalPrivateKey((ElGamalPrivateKey)key);
    }

    throw new InvalidKeyException("key type unknown");
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:24,代碼來源:KeyFactorySpi.java

示例3: initKey

import javax.crypto.interfaces.DHPrivateKey; //導入依賴的package包/類
/**
 * 甲方初始化並返回密鑰對
 */
public static Map<String, Object> initKey() throws Exception{
	//實例化密鑰對生成器
	KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DH");
	//初始化密鑰對生成器  默認是1024  512-1024 & 64的倍數
	keyPairGenerator.initialize(1024);
	//生成密鑰對
	KeyPair keyPair = keyPairGenerator.generateKeyPair();
	//得到甲方公鑰
	DHPublicKey publicKey = (DHPublicKey) keyPair.getPublic();
	//得到甲方私鑰
	DHPrivateKey peivateKey = (DHPrivateKey) keyPair.getPrivate();
	//將公鑰和私鑰封裝到Map中,方便之後使用
	Map<String, Object> keyMap = new HashMap<String, Object>();
	keyMap.put(PUBLIC_KEY, publicKey);
	keyMap.put(PRIVATE_KEY, peivateKey);
	return keyMap;
}
 
開發者ID:laidu,項目名稱:java-learn,代碼行數:21,代碼來源:DHUtil.java

示例4: loadServerKey

import javax.crypto.interfaces.DHPrivateKey; //導入依賴的package包/類
public void loadServerKey() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException, NoSuchProviderException, InvalidAlgorithmParameterException, InvalidKeySpecException {
		char[] password = KEYSTORE_PASSWORD.toCharArray();

		FileInputStream fIn = new FileInputStream(KEYSTORE_FILENAME);
		KeyStore keystore = KeyStore.getInstance("JKS");

		keystore.load(fIn, password);
		serverCertificate = (X509Certificate) keystore.getCertificate("server");
		serverPrivateKey  = (PrivateKey) keystore.getKey("server", password);
		
		// Generate DH keys for this session
		// Use hardcoded DH parameters
		DHParameterSpec dhParams = new DHParameterSpec(new BigInteger(new byte[] {(byte)0x00, (byte)0xad, (byte)0x77, (byte)0xcd, (byte)0xb7, (byte)0x14, (byte)0x6f, (byte)0xfe, (byte)0x08, (byte)0x1a, (byte)0xee, (byte)0xd2, (byte)0x2c, (byte)0x18, (byte)0x29, (byte)0x62, (byte)0x5a, (byte)0xff, (byte)0x03, (byte)0x5d, (byte)0xde, (byte)0xba, (byte)0x0d, (byte)0xd4, (byte)0x36, (byte)0x15, (byte)0x03, (byte)0x11, (byte)0x21, (byte)0x48, (byte)0xd9, (byte)0x77, (byte)0xfb, (byte)0x67, (byte)0xb0, (byte)0x74, (byte)0x2e, (byte)0x68, (byte)0xed, (byte)0x5a, (byte)0x3f, (byte)0x8a, (byte)0x3e, (byte)0xdb, (byte)0x81, (byte)0xa3, (byte)0x3b, (byte)0xaf, (byte)0x26, (byte)0xe4, (byte)0x54, (byte)0x00, (byte)0x85, (byte)0x0d, (byte)0xfd, (byte)0x23, (byte)0x21, (byte)0xc1, (byte)0xfe, (byte)0x69, (byte)0xe4, (byte)0xf3, (byte)0x57, (byte)0xe6, (byte)0x0a, (byte)0x7c, (byte)0x62, (byte)0xc0, (byte)0xd6, (byte)0x40, (byte)0x3e, (byte)0x94, (byte)0x9e, (byte)0x49, (byte)0x72, (byte)0x5a, (byte)0x21, (byte)0x53, (byte)0xb0, (byte)0x83, (byte)0x05, (byte)0x81, (byte)0x5a, (byte)0xde, (byte)0x17, (byte)0x31, (byte)0xbf, (byte)0xa8, (byte)0xa9, (byte)0xe5, (byte)0x28, (byte)0x1a, (byte)0xfc, (byte)0x06, (byte)0x1e, (byte)0x49, (byte)0xfe, (byte)0xdc, (byte)0x08, (byte)0xe3, (byte)0x29, (byte)0xfe, (byte)0x5b, (byte)0x88, (byte)0x66, (byte)0x39, (byte)0xa8, (byte)0x69, (byte)0x62, (byte)0x88, (byte)0x47, (byte)0x36, (byte)0xf5, (byte)0xdd, (byte)0x92, (byte)0x8f, (byte)0xca, (byte)0x32, (byte)0x4b, (byte)0x87, (byte)0xad, (byte)0xbf, (byte)0xab, (byte)0x4a, (byte)0x9d, (byte)0xd5, (byte)0xb8, (byte)0x2c, (byte)0xc4, (byte)0x43, (byte)0xb2, (byte)0x21, (byte)0xb4, (byte)0x2a, (byte)0x9b, (byte)0x42, (byte)0x17, (byte)0x6d, (byte)0xb6, (byte)0x86, (byte)0x42, (byte)0x41, (byte)0xb1, (byte)0xc7, (byte)0x37, (byte)0x37, (byte)0x95, (byte)0x6d, (byte)0x62, (byte)0xca, (byte)0xa6, (byte)0x57, (byte)0x33, (byte)0x88, (byte)0xe2, (byte)0x31, (byte)0xfe, (byte)0xd1, (byte)0x51, (byte)0xe7, (byte)0x73, (byte)0xae, (byte)0x3c, (byte)0xa7, (byte)0x4b, (byte)0xbc, (byte)0x8a, (byte)0x3d, (byte)0xc5, (byte)0x9a, (byte)0x28, (byte)0x9a, (byte)0xf9, (byte)0x57, (byte)0xb6, (byte)0xec, (byte)0xf6, (byte)0x75, (byte)0xaa, (byte)0x56, (byte)0xc1, (byte)0x42, (byte)0x9f, (byte)0x6a, (byte)0x7c, (byte)0x91, (byte)0x8b, (byte)0x5e, (byte)0xea, (byte)0x54, (byte)0x32, (byte)0x90, (byte)0x8a, (byte)0x9d, (byte)0x76, (byte)0x2a, (byte)0x29, (byte)0x1b, (byte)0x84, (byte)0x35, (byte)0xe6, (byte)0x21, (byte)0x07, (byte)0xb2, (byte)0xcb, (byte)0x5c, (byte)0xf9, (byte)0x5b, (byte)0xe9, (byte)0x5e, (byte)0x1b, (byte)0x80, (byte)0xd5, (byte)0x53, (byte)0xd7, (byte)0xa4, (byte)0x26, (byte)0x58, (byte)0xe4, (byte)0xe9, (byte)0x3f, (byte)0xfd, (byte)0xeb, (byte)0x78, (byte)0xf2, (byte)0x25, (byte)0x02, (byte)0x42, (byte)0xf8, (byte)0x50, (byte)0x13, (byte)0xbb, (byte)0x01, (byte)0x39, (byte)0xf3, (byte)0xcf, (byte)0x5c, (byte)0x51, (byte)0xdf, (byte)0xed, (byte)0xc5, (byte)0xfa, (byte)0xd8, (byte)0x4f, (byte)0xae, (byte)0x76, (byte)0xe8, (byte)0x30, (byte)0xfc, (byte)0x85, (byte)0xaa, (byte)0x8c, (byte)0x91, (byte)0x02, (byte)0x2b, (byte)0x61, (byte)0x87
}), new BigInteger(new byte[] { 0x05 }));
		
	    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DiffieHellman");
	    keyPairGenerator.initialize(dhParams);
	    
	    KeyPair keyPair = keyPairGenerator.generateKeyPair();
	    dhPubKey = (DHPublicKey)keyPair.getPublic();
	    dhPrivateKey = (DHPrivateKey)keyPair.getPrivate();
	}
 
開發者ID:jderuiter,項目名稱:statelearner,代碼行數:23,代碼來源:TLSTestService.java

示例5: loadClientKey

import javax.crypto.interfaces.DHPrivateKey; //導入依賴的package包/類
public void loadClientKey() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException, InvalidAlgorithmParameterException {
		char[] password = KEYSTORE_PASSWORD.toCharArray();

		FileInputStream fIn = new FileInputStream(KEYSTORE_FILENAME);
		KeyStore keystore = KeyStore.getInstance("JKS");

		keystore.load(fIn, password);
		clientCertificate = (X509Certificate) keystore.getCertificate("client");
		clientPrivateKey  = (PrivateKey) keystore.getKey("client", password);
		
		// Generate DH keys for this session
		// Use hardcoded DH parameters
		DHParameterSpec dhParams = new DHParameterSpec(new BigInteger(new byte[] {(byte)0x00, (byte)0xad, (byte)0x77, (byte)0xcd, (byte)0xb7, (byte)0x14, (byte)0x6f, (byte)0xfe, (byte)0x08, (byte)0x1a, (byte)0xee, (byte)0xd2, (byte)0x2c, (byte)0x18, (byte)0x29, (byte)0x62, (byte)0x5a, (byte)0xff, (byte)0x03, (byte)0x5d, (byte)0xde, (byte)0xba, (byte)0x0d, (byte)0xd4, (byte)0x36, (byte)0x15, (byte)0x03, (byte)0x11, (byte)0x21, (byte)0x48, (byte)0xd9, (byte)0x77, (byte)0xfb, (byte)0x67, (byte)0xb0, (byte)0x74, (byte)0x2e, (byte)0x68, (byte)0xed, (byte)0x5a, (byte)0x3f, (byte)0x8a, (byte)0x3e, (byte)0xdb, (byte)0x81, (byte)0xa3, (byte)0x3b, (byte)0xaf, (byte)0x26, (byte)0xe4, (byte)0x54, (byte)0x00, (byte)0x85, (byte)0x0d, (byte)0xfd, (byte)0x23, (byte)0x21, (byte)0xc1, (byte)0xfe, (byte)0x69, (byte)0xe4, (byte)0xf3, (byte)0x57, (byte)0xe6, (byte)0x0a, (byte)0x7c, (byte)0x62, (byte)0xc0, (byte)0xd6, (byte)0x40, (byte)0x3e, (byte)0x94, (byte)0x9e, (byte)0x49, (byte)0x72, (byte)0x5a, (byte)0x21, (byte)0x53, (byte)0xb0, (byte)0x83, (byte)0x05, (byte)0x81, (byte)0x5a, (byte)0xde, (byte)0x17, (byte)0x31, (byte)0xbf, (byte)0xa8, (byte)0xa9, (byte)0xe5, (byte)0x28, (byte)0x1a, (byte)0xfc, (byte)0x06, (byte)0x1e, (byte)0x49, (byte)0xfe, (byte)0xdc, (byte)0x08, (byte)0xe3, (byte)0x29, (byte)0xfe, (byte)0x5b, (byte)0x88, (byte)0x66, (byte)0x39, (byte)0xa8, (byte)0x69, (byte)0x62, (byte)0x88, (byte)0x47, (byte)0x36, (byte)0xf5, (byte)0xdd, (byte)0x92, (byte)0x8f, (byte)0xca, (byte)0x32, (byte)0x4b, (byte)0x87, (byte)0xad, (byte)0xbf, (byte)0xab, (byte)0x4a, (byte)0x9d, (byte)0xd5, (byte)0xb8, (byte)0x2c, (byte)0xc4, (byte)0x43, (byte)0xb2, (byte)0x21, (byte)0xb4, (byte)0x2a, (byte)0x9b, (byte)0x42, (byte)0x17, (byte)0x6d, (byte)0xb6, (byte)0x86, (byte)0x42, (byte)0x41, (byte)0xb1, (byte)0xc7, (byte)0x37, (byte)0x37, (byte)0x95, (byte)0x6d, (byte)0x62, (byte)0xca, (byte)0xa6, (byte)0x57, (byte)0x33, (byte)0x88, (byte)0xe2, (byte)0x31, (byte)0xfe, (byte)0xd1, (byte)0x51, (byte)0xe7, (byte)0x73, (byte)0xae, (byte)0x3c, (byte)0xa7, (byte)0x4b, (byte)0xbc, (byte)0x8a, (byte)0x3d, (byte)0xc5, (byte)0x9a, (byte)0x28, (byte)0x9a, (byte)0xf9, (byte)0x57, (byte)0xb6, (byte)0xec, (byte)0xf6, (byte)0x75, (byte)0xaa, (byte)0x56, (byte)0xc1, (byte)0x42, (byte)0x9f, (byte)0x6a, (byte)0x7c, (byte)0x91, (byte)0x8b, (byte)0x5e, (byte)0xea, (byte)0x54, (byte)0x32, (byte)0x90, (byte)0x8a, (byte)0x9d, (byte)0x76, (byte)0x2a, (byte)0x29, (byte)0x1b, (byte)0x84, (byte)0x35, (byte)0xe6, (byte)0x21, (byte)0x07, (byte)0xb2, (byte)0xcb, (byte)0x5c, (byte)0xf9, (byte)0x5b, (byte)0xe9, (byte)0x5e, (byte)0x1b, (byte)0x80, (byte)0xd5, (byte)0x53, (byte)0xd7, (byte)0xa4, (byte)0x26, (byte)0x58, (byte)0xe4, (byte)0xe9, (byte)0x3f, (byte)0xfd, (byte)0xeb, (byte)0x78, (byte)0xf2, (byte)0x25, (byte)0x02, (byte)0x42, (byte)0xf8, (byte)0x50, (byte)0x13, (byte)0xbb, (byte)0x01, (byte)0x39, (byte)0xf3, (byte)0xcf, (byte)0x5c, (byte)0x51, (byte)0xdf, (byte)0xed, (byte)0xc5, (byte)0xfa, (byte)0xd8, (byte)0x4f, (byte)0xae, (byte)0x76, (byte)0xe8, (byte)0x30, (byte)0xfc, (byte)0x85, (byte)0xaa, (byte)0x8c, (byte)0x91, (byte)0x02, (byte)0x2b, (byte)0x61, (byte)0x87
}), new BigInteger(new byte[] { 0x05 }));
		
	    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DiffieHellman");
	    keyPairGenerator.initialize(dhParams);
	    
	    KeyPair keyPair = keyPairGenerator.generateKeyPair();
	    dhPubKey = (DHPublicKey)keyPair.getPublic();
	    dhPrivateKey = (DHPrivateKey)keyPair.getPrivate();
	}
 
開發者ID:jderuiter,項目名稱:statelearner,代碼行數:23,代碼來源:TLSTestService.java

示例6: initDiffieHellman

import javax.crypto.interfaces.DHPrivateKey; //導入依賴的package包/類
protected void initDiffieHellman(DHPrivateKey dhKey, SecureRandom random)
  throws SSLException
{
  try
    {
      keyAgreement = KeyAgreement.getInstance("DH");
      keyAgreement.init(dhKey, random);
    }
  catch (InvalidKeyException ike)
    {
      throw new SSLException(ike);
    }
  catch (NoSuchAlgorithmException nsae)
    {
      throw new SSLException(nsae);
    }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:18,代碼來源:AbstractHandshake.java

示例7: initKey

import javax.crypto.interfaces.DHPrivateKey; //導入依賴的package包/類
/**
 * 初始化甲方密鑰
 * @return Map 甲方密鑰Map
 * @throws Exception
 */
public static Map<String,Object> initKey()throws Exception{
	// 實例化密鑰對生成器
	KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_ALGORITHM);
	keyPairGenerator.initialize(KEY_SIZE);
	// 生成密鑰對
	KeyPair keyPair = keyPairGenerator.generateKeyPair();
	//甲方公鑰
	DHPublicKey publicKey = (DHPublicKey) keyPair.getPublic();
	//甲方私鑰
	DHPrivateKey privateKey = (DHPrivateKey) keyPair.getPrivate();
	//將密鑰對存儲在Map中
	Map<String,Object> keyMap = new HashMap<String,Object>();
	keyMap.put(PUBLIC_KEY, publicKey);
	keyMap.put(PRIVATE_KEY, privateKey);
	return keyMap;
}
 
開發者ID:DISSIDIA-986,項目名稱:EncDecAboutJava,代碼行數:22,代碼來源:DHCoder.java

示例8: initKey

import javax.crypto.interfaces.DHPrivateKey; //導入依賴的package包/類
/**
 * 初始化甲方密鑰
 * 
 * @return
 * @throws Exception
 */
public static Map<String, Object> initKey() throws Exception {
    KeyPairGenerator keyPairGenerator = KeyPairGenerator
            .getInstance(ALGORITHM);
    keyPairGenerator.initialize(KEY_SIZE);
 
    KeyPair keyPair = keyPairGenerator.generateKeyPair();
 
    // 甲方公鑰
    DHPublicKey publicKey = (DHPublicKey) keyPair.getPublic();
 
    // 甲方私鑰
    DHPrivateKey privateKey = (DHPrivateKey) keyPair.getPrivate();
 
    Map<String, Object> keyMap = new HashMap<String, Object>(2);
 
    keyMap.put(PUBLIC_KEY, publicKey);
    keyMap.put(PRIVATE_KEY, privateKey);
    return keyMap;
}
 
開發者ID:zhanggh,項目名稱:mtools,代碼行數:26,代碼來源:DHCoder.java

示例9: generateDHPublicKey

import javax.crypto.interfaces.DHPrivateKey; //導入依賴的package包/類
public byte[] generateDHPublicKey() throws NoSuchAlgorithmException,
        InvalidAlgorithmParameterException, InvalidKeyException {

    // generate key pair
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("DH");
    DHParameterSpec param = new DHParameterSpec(sP, sG);
    kpg.initialize(param);
    KeyPair kp = kpg.generateKeyPair();
    DHPrivateKey privateKey = (DHPrivateKey) kp.getPrivate();
    DHPublicKey publicKey = (DHPublicKey) kp.getPublic();

    // initialize key agreement with our private key
    mKA = KeyAgreement.getInstance("DH");
    mKA.init(privateKey);

    // return our public 1/2 key to share
    return getBytes(publicKey.getY());
}
 
開發者ID:SafeSlingerProject,項目名稱:exchange-android,代碼行數:19,代碼來源:CryptoAccess.java

示例10: initKey

import javax.crypto.interfaces.DHPrivateKey; //導入依賴的package包/類
/**
 * 初始化甲方密鑰
 * 
 * @return
 * @throws Exception
 */
public static Map<String, Object> initKey() throws Exception {
    KeyPairGenerator keyPairGenerator = KeyPairGenerator
            .getInstance(ALGORITHM);
    keyPairGenerator.initialize(KEY_SIZE);

    KeyPair keyPair = keyPairGenerator.generateKeyPair();

    // 甲方公鑰
    DHPublicKey publicKey = (DHPublicKey) keyPair.getPublic();

    // 甲方私鑰
    DHPrivateKey privateKey = (DHPrivateKey) keyPair.getPrivate();

    Map<String, Object> keyMap = new HashMap<String, Object>(2);

    keyMap.put(PUBLIC_KEY, publicKey);
    keyMap.put(PRIVATE_KEY, privateKey);
    return keyMap;
}
 
開發者ID:cheyiliu,項目名稱:test4java,代碼行數:26,代碼來源:DHCoder.java

示例11: getHashedSharedSecret

import javax.crypto.interfaces.DHPrivateKey; //導入依賴的package包/類
private byte[] getHashedSharedSecret ( final String base64PublicKey )
  throws IOException
{
  Preconditions.checkNotNull(base64PublicKey, "base64PublicKey required");

  try {
    DHPublicKey publicKey =
        (DHPublicKey) KeyFactory.getInstance("DH").generatePublic(
            new DHPublicKeySpec(new BigInteger(Base64.decode(
                base64PublicKey.toCharArray(), false)),
                DEFAULT_DH_SPEC.getP(), DEFAULT_DH_SPEC.getG()));

    BigInteger zz =
        publicKey.getY().modPow(((DHPrivateKey) keyPair.getPrivate()).getX(),
            DEFAULT_DH_SPEC.getP());

    return MessageDigest.getInstance(algorithm.getName()).digest(zz.toByteArray());
  } catch ( GeneralSecurityException e ) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:calebrichardson,項目名稱:spiff,代碼行數:22,代碼來源:DhSession.java

示例12: generatePrivateKeyParameter

import javax.crypto.interfaces.DHPrivateKey; //導入依賴的package包/類
static public AsymmetricKeyParameter generatePrivateKeyParameter(
    PrivateKey    key)
    throws InvalidKeyException
{
    if (key instanceof DHPrivateKey)
    {
        DHPrivateKey    k = (DHPrivateKey)key;

        return new DHPrivateKeyParameters(k.getX(),
            new DHParameters(k.getParams().getP(), k.getParams().getG(), null, k.getParams().getL()));
    }
                    
    throw new InvalidKeyException("can't identify DH private key.");
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:15,代碼來源:DHUtil.java

示例13: engineTranslateKey

import javax.crypto.interfaces.DHPrivateKey; //導入依賴的package包/類
protected Key engineTranslateKey(
    Key key)
    throws InvalidKeyException
{
    if (key instanceof DHPublicKey)
    {
        return new BCDHPublicKey((DHPublicKey)key);
    }
    else if (key instanceof DHPrivateKey)
    {
        return new BCDHPrivateKey((DHPrivateKey)key);
    }

    throw new InvalidKeyException("key type unknown");
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:16,代碼來源:KeyFactorySpi.java

示例14: equals

import javax.crypto.interfaces.DHPrivateKey; //導入依賴的package包/類
public boolean equals(
    Object o)
{
    if (!(o instanceof DHPrivateKey))
    {
        return false;
    }

    DHPrivateKey other = (DHPrivateKey)o;

    return this.getX().equals(other.getX())
        && this.getParams().getG().equals(other.getParams().getG())
        && this.getParams().getP().equals(other.getParams().getP())
        && this.getParams().getL() == other.getParams().getL();
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:16,代碼來源:BCDHPrivateKey.java

示例15: SymmetricKeyGenerator

import javax.crypto.interfaces.DHPrivateKey; //導入依賴的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


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