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


Java DHPublicKey.getY方法代碼示例

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


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

示例1: testPublicKey

import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
public void testPublicKey() throws AssociationException
{
    DHParameterSpec dhParameterSpec = DiffieHellmanSession.getDefaultParameter();

    DiffieHellmanSession diffieHellmanSession = DiffieHellmanSession.create(AssociationSessionType.DH_SHA1, dhParameterSpec);

    String dhPublicKeyBase64 = diffieHellmanSession.getPublicKey();

    DHPublicKey dhPublicKey = diffieHellmanSession.stringToPublicKey(dhPublicKeyBase64);

    BigInteger two = new BigInteger("2");
    BigInteger y = dhPublicKey.getY();
    BigInteger p = dhParameterSpec.getP();

    assertTrue(y.compareTo(two) != -1);
    assertTrue(y.compareTo(p) == -1);
}
 
開發者ID:jbufu,項目名稱:openid4java,代碼行數:18,代碼來源:DiffieHellmanSessionTest.java

示例2: getPublicKey

import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
/**
 * Returns the public key for a given key pair.
 * 
 * @param keyPair
 * @return public key
 */
protected static byte[] getPublicKey(KeyPair keyPair) {
	 DHPublicKey incomingPublicKey = (DHPublicKey) keyPair.getPublic();
     BigInteger	dhY = incomingPublicKey.getY();
     log.debug("Public key: {}", dhY);
     byte[] result = dhY.toByteArray();
     log.debug("Public key as bytes - length [{}]: {}", result.length, Hex.encodeHexString(result));
     byte[] temp = new byte[KEY_LENGTH];
     if (result.length < KEY_LENGTH) {
    	 System.arraycopy(result, 0, temp, KEY_LENGTH - result.length, result.length);
    	 result = temp;
    	 log.debug("Padded public key length to 128");
     } else if(result.length > KEY_LENGTH){
    	 System.arraycopy(result, result.length - KEY_LENGTH, temp, 0, KEY_LENGTH);
    	 result = temp;
    	 log.debug("Truncated public key length to 128");
     }
     return result;
}
 
開發者ID:cwpenhale,項目名稱:red5-mobileconsole,代碼行數:25,代碼來源:RTMPHandshake.java

示例3: generatePublicKeyParameter

import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
static public AsymmetricKeyParameter generatePublicKeyParameter(
    PublicKey    key)
    throws InvalidKeyException
{
    if (key instanceof DHPublicKey)
    {
        DHPublicKey    k = (DHPublicKey)key;

        return new DHPublicKeyParameters(k.getY(),
            new DHParameters(k.getParams().getP(), k.getParams().getG(), null, k.getParams().getL()));
    }

    throw new InvalidKeyException("can't identify DH public key.");
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:15,代碼來源:DHUtil.java

示例4: getDHPublicKeySpec

import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
static DHPublicKeySpec getDHPublicKeySpec(PublicKey key) {
    if (key instanceof DHPublicKey) {
        DHPublicKey dhKey = (DHPublicKey)key;
        DHParameterSpec params = dhKey.getParams();
        return new DHPublicKeySpec(dhKey.getY(),
                                params.getP(), params.getG());
    }
    try {
        KeyFactory factory = JsseJce.getKeyFactory("DH");
        return factory.getKeySpec(key, DHPublicKeySpec.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:15,代碼來源:DHCrypt.java

示例5: validateDHPublicKey

import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
/**
 * Returns whether the Diffie-Hellman public key is valid or not.
 *
 * Per RFC 2631 and NIST SP800-56A, the following algorithm is used to
 * validate Diffie-Hellman public keys:
 * 1. Verify that y lies within the interval [2,p-1]. If it does not,
 *    the key is invalid.
 * 2. Compute y^q mod p. If the result == 1, the key is valid.
 *    Otherwise the key is invalid.
 */
private static void validateDHPublicKey(DHPublicKey publicKey)
        throws InvalidKeyException {
    DHParameterSpec paramSpec = publicKey.getParams();

    BigInteger p = paramSpec.getP();
    BigInteger g = paramSpec.getG();
    BigInteger y = publicKey.getY();

    validateDHPublicKey(p, g, y);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:KeyUtil.java

示例6: getDHPublicKeySpec

import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
static DHPublicKeySpec getDHPublicKeySpec(PublicKey key) {
    if (key instanceof DHPublicKey) {
        DHPublicKey dhKey = (DHPublicKey)key;
        DHParameterSpec params = dhKey.getParams();
        return new DHPublicKeySpec(dhKey.getY(),
                                params.getP(), params.getG());
    }
    try {
        KeyFactory factory = JsseJce.getKeyFactory("DiffieHellman");
        return factory.getKeySpec(key, DHPublicKeySpec.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:DHCrypt.java

示例7: implRun

import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
protected void implRun()
  throws NoSuchAlgorithmException, InvalidAlgorithmParameterException,
         InvalidKeyException, SignatureException
{
  KeyPairGenerator dhGen = KeyPairGenerator.getInstance("DH");
  DHParameterSpec dhparams = DiffieHellman.getParams().getParams();
  dhGen.initialize(dhparams, engine.session().random());
  dhPair = dhGen.generateKeyPair();
  DHPublicKey pub = (DHPublicKey) dhPair.getPublic();

  // Generate the parameters message.
  ServerDHParams params = new ServerDHParams(pub.getParams().getP(),
                                             pub.getParams().getG(),
                                             pub.getY());
  paramsBuffer = params.buffer();

  // Sign the parameters, if needed.
  if (engine.session().suite.signatureAlgorithm() != SignatureAlgorithm.ANONYMOUS)
    {
      sigBuffer = signParams(paramsBuffer);
      paramsBuffer.rewind();
    }
  if (Debug.DEBUG_KEY_EXCHANGE)
    logger.logv(Component.SSL_KEY_EXCHANGE,
                "Diffie-Hellman public:{0} private:{1}",
                dhPair.getPublic(), dhPair.getPrivate());
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:28,代碼來源:ServerHandshake.java

示例8: implRun

import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
protected void implRun()
  throws NoSuchAlgorithmException, InvalidAlgorithmParameterException,
         InvalidKeyException, SignatureException
{
  KeyPairGenerator dhGen = KeyPairGenerator.getInstance("DH");
  DHParameterSpec dhparams = DiffieHellman.getParams().getParams();
  dhGen.initialize(dhparams, engine.session().random());
  dhPair = dhGen.generateKeyPair();
  DHPublicKey pub = (DHPublicKey) dhPair.getPublic();
  
  // Generate the parameters message.
  ServerDHParams params = new ServerDHParams(pub.getParams().getP(),
                                             pub.getParams().getG(),
                                             pub.getY());
  paramsBuffer = params.buffer();
  
  // Sign the parameters, if needed.
  if (engine.session().suite.signatureAlgorithm() != SignatureAlgorithm.ANONYMOUS)
    {
      sigBuffer = signParams(paramsBuffer);
      paramsBuffer.rewind();
    }
  if (Debug.DEBUG_KEY_EXCHANGE)
    logger.logv(Component.SSL_KEY_EXCHANGE,
                "Diffie-Hellman public:{0} private:{1}",
                dhPair.getPublic(), dhPair.getPrivate());
}
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:28,代碼來源:ServerHandshake.java

示例9: getDigestedZZ

import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
protected byte[] getDigestedZZ(String otherPublicKeyBase64)
{
    DHPublicKey  dhPublicKey  = stringToPublicKey(otherPublicKeyBase64);
    DHPrivateKey dhPrivateKey = getPrivateKey();
    BigInteger xa = dhPrivateKey.getX();
    BigInteger yb = dhPublicKey.getY();
    BigInteger p  = _dhParameterSpec.getP();

    BigInteger zz = yb.modPow(xa, p);

    return _hDigest.digest(zz.toByteArray());
}
 
開發者ID:jbufu,項目名稱:openid4java,代碼行數:13,代碼來源:DiffieHellmanSession.java

示例10: buildDH

import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
static byte []
buildDH(DHPublicKey key) {
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	BigInteger p = key.getParams().getP();
	BigInteger g = key.getParams().getG();
	BigInteger y = key.getY();

	int pLength, gLength, yLength;
	if (g.equals(TWO) && (p.equals(DHPRIME768) || p.equals(DHPRIME1024))) {
		pLength = 1;
		gLength = 0;
	}
	else {
		pLength = BigIntegerLength(p);
		gLength = BigIntegerLength(g);
	}
	yLength = BigIntegerLength(y);

	writeShort(out, pLength);
	if (pLength == 1) {
		if (p.bitLength() == 768)
			out.write(1);
		else
			out.write(2);
	}
	else
		writeBigInteger(out, p);
	writeShort(out, gLength);
	if (gLength > 0)
		writeBigInteger(out, g);
	writeShort(out, yLength);
	writeBigInteger(out, y);

	return out.toByteArray();
}
 
開發者ID:epam,項目名稱:Wilma,代碼行數:36,代碼來源:KEYConverter.java

示例11: initKeyPair

import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
private void initKeyPair() {
    final DHParameterSpec keySpec = new DHParameterSpec(DH_MODULUS, DH_BASE);
    final KeyPair keyPair;
    try {
        KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH");
        keyGen.initialize(keySpec);
        keyPair = keyGen.generateKeyPair();
        keyAgreement = KeyAgreement.getInstance("DH");
        keyAgreement.init(keyPair.getPrivate());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // extract public key bytes
    DHPublicKey publicKey = (DHPublicKey) keyPair.getPublic();
    BigInteger dh_Y = publicKey.getY();
    ownPublicKey = dh_Y.toByteArray();
    byte[] temp = new byte[PUBLIC_KEY_SIZE];
    if (ownPublicKey.length < PUBLIC_KEY_SIZE) {
        // pad zeros on left
        System.arraycopy(ownPublicKey, 0, temp, PUBLIC_KEY_SIZE - ownPublicKey.length, ownPublicKey.length);
        ownPublicKey = temp;
    } else if (ownPublicKey.length > PUBLIC_KEY_SIZE) {
        // truncate zeros from left
        System.arraycopy(ownPublicKey, ownPublicKey.length - PUBLIC_KEY_SIZE, temp, 0, PUBLIC_KEY_SIZE);
        ownPublicKey = temp;
    }
}
 
開發者ID:diohpix,項目名稱:flazr-fork,代碼行數:28,代碼來源:RtmpHandshake.java

示例12: getPublicKey

import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
/**
 * Returns the public key for a given key pair.
 * 
 * @param keyPair key pair
 * @return public key
 */
protected byte[] getPublicKey(KeyPair keyPair) {
    DHPublicKey incomingPublicKey = (DHPublicKey) keyPair.getPublic();
    BigInteger dhY = incomingPublicKey.getY();
    if (log.isDebugEnabled()) {
        log.debug("Public key: {}", Hex.encodeHexString(BigIntegers.asUnsignedByteArray(dhY)));
    }
    return Arrays.copyOfRange(BigIntegers.asUnsignedByteArray(dhY), 0, KEY_LENGTH);
}
 
開發者ID:Red5,項目名稱:red5-server-common,代碼行數:15,代碼來源:RTMPHandshake.java

示例13: getDHPublicKeySpec

import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
static DHPublicKeySpec getDHPublicKeySpec(PublicKey key) {
    if (key instanceof DHPublicKey) {
        DHPublicKey dhKey = (DHPublicKey)key;
        DHParameterSpec params = dhKey.getParams();
        return new DHPublicKeySpec(dhKey.getY(), params.getP(), params.getG());
    }
    try {
        KeyFactory factory = JsseJce.getKeyFactory("DH");
        return factory.getKeySpec(key, DHPublicKeySpec.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:aducode,項目名稱:openjdk-source-code-learn,代碼行數:14,代碼來源:DHCrypt.java

示例14: JCEDHPublicKey

import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
JCEDHPublicKey(
    DHPublicKey    key)
{
    this.y = key.getY();
    this.dhSpec = key.getParams();
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:7,代碼來源:JCEDHPublicKey.java

示例15: JCEElGamalPublicKey

import javax.crypto.interfaces.DHPublicKey; //導入方法依賴的package包/類
JCEElGamalPublicKey(
    DHPublicKey    key)
{
    this.y = key.getY();
    this.elSpec = new ElGamalParameterSpec(key.getParams().getP(), key.getParams().getG());
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:7,代碼來源:JCEElGamalPublicKey.java


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