当前位置: 首页>>代码示例>>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;未经允许,请勿转载。