当前位置: 首页>>代码示例>>Java>>正文


Java DHPublicKey.getParams方法代码示例

本文整理汇总了Java中javax.crypto.interfaces.DHPublicKey.getParams方法的典型用法代码示例。如果您正苦于以下问题:Java DHPublicKey.getParams方法的具体用法?Java DHPublicKey.getParams怎么用?Java DHPublicKey.getParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.crypto.interfaces.DHPublicKey的用法示例。


在下文中一共展示了DHPublicKey.getParams方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: engineDoPhase

import javax.crypto.interfaces.DHPublicKey; //导入方法依赖的package包/类
protected Key engineDoPhase(
    Key     key,
    boolean lastPhase) 
    throws InvalidKeyException, IllegalStateException
{
    if (x == null)
    {
        throw new IllegalStateException("Diffie-Hellman not initialised.");
    }

    if (!(key instanceof DHPublicKey))
    {
        throw new InvalidKeyException("DHKeyAgreement doPhase requires DHPublicKey");
    }
    DHPublicKey pubKey = (DHPublicKey)key;

    if (!pubKey.getParams().getG().equals(g) || !pubKey.getParams().getP().equals(p))
    {
        throw new InvalidKeyException("DHPublicKey not for this KeyAgreement!");
    }

    if (lastPhase)
    {
        result = ((DHPublicKey)key).getY().modPow(x, p);
        return null;
    }
    else
    {
        result = ((DHPublicKey)key).getY().modPow(x, p);
    }

    return new BCDHPublicKey(result, pubKey.getParams());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:34,代码来源:KeyAgreementSpi.java

示例2: initKey

import javax.crypto.interfaces.DHPublicKey; //导入方法依赖的package包/类
/**
 * 乙方根据甲方公钥初始化并返回密钥对
 */
public static Map<String, Object> initKey(byte[] key) throws Exception{
	//将甲方公钥从字节数组转换为publicKey
	X509EncodedKeySpec keySpec = new X509EncodedKeySpec(key);
	//实例化密钥工厂
	KeyFactory keyFactory = KeyFactory.getInstance("DH");
	//产生甲方公钥pubKey
	DHPublicKey dhPublicKey = (DHPublicKey) keyFactory.generatePublic(keySpec);
	//剖析甲方公钥,得到其参数
	DHParameterSpec dhParameterSpec = dhPublicKey.getParams();
	//实例化密钥对生成器
	KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DH");
	//用甲方公钥初始化密钥对生成器
	keyPairGenerator.initialize(dhParameterSpec);
	//产生密钥对
	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:laidu,项目名称:java-learn,代码行数:30,代码来源:DHUtil.java

示例3: 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

示例4: 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

示例5: 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

示例6: createKeys

import javax.crypto.interfaces.DHPublicKey; //导入方法依赖的package包/类
/**
 * Create a set of public/private keys using ValueLinks defined parameters
 * @return KeyPair object containing both public and private keys
 * @throws NoSuchAlgorithmException
 * @throws InvalidAlgorithmParameterException
 */
public KeyPair createKeys() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeySpecException {
    // initialize the parameter spec
    DHPublicKey publicKey = (DHPublicKey) this.getValueLinkPublicKey();
    DHParameterSpec dhParamSpec = publicKey.getParams();
    //Debug.logInfo(dhParamSpec.getP().toString() + " / " + dhParamSpec.getG().toString(), module);

    // create the public/private key pair using parameters defined by valuelink
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH");
    keyGen.initialize(dhParamSpec);
    KeyPair keyPair = keyGen.generateKeyPair();

    return keyPair;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:20,代码来源:ValueLinkApi.java

示例7: engineDoPhase

import javax.crypto.interfaces.DHPublicKey; //导入方法依赖的package包/类
protected Key engineDoPhase(Key incoming, boolean lastPhase)
    throws InvalidKeyException
{
  if (key == null)
    throw new IllegalStateException("Not initialized");

  if (last_phase_done)
    throw new IllegalStateException("Last phase already done");

  if (! (incoming instanceof DHPublicKey))
    throw new InvalidKeyException("Key MUST be a DHPublicKey");

  DHPublicKey pub = (DHPublicKey) incoming;
  DHParameterSpec s1 = key.getParams();
  DHParameterSpec s2 = pub.getParams();
  if (! s1.getG().equals(s2.getG()) || ! s1.getP().equals(s2.getP()))
    throw new InvalidKeyException("Incompatible key");
  if (! lastPhase)
    throw new IllegalArgumentException(
        "This key-agreement MUST be concluded in one step only");
  BigInteger resultBI = pub.getY().modPow(key.getX(), s1.getP());
  result = resultBI.toByteArray();
  if (result[0] == 0x00)
    {
      byte[] buf = new byte[result.length - 1];
      System.arraycopy(result, 1, buf, 0, buf.length);
      result = buf;
    }
  last_phase_done = true;
  return null;
}
 
开发者ID:vilie,项目名称:javify,代码行数:32,代码来源:DiffieHellmanImpl.java

示例8: 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:openjdk,项目名称:jdk7-jdk,代码行数:14,代码来源:DHCrypt.java

示例9: engineDoPhase

import javax.crypto.interfaces.DHPublicKey; //导入方法依赖的package包/类
protected Key engineDoPhase(
    Key     key,
    boolean lastPhase) 
    throws InvalidKeyException, IllegalStateException
{
    if (x == null)
    {
        throw new IllegalStateException("Diffie-Hellman not initialised.");
    }

    if (!(key instanceof DHPublicKey))
    {
        throw new InvalidKeyException("DHKeyAgreement doPhase requires DHPublicKey");
    }
    DHPublicKey pubKey = (DHPublicKey)key;

    if (!pubKey.getParams().getG().equals(g) || !pubKey.getParams().getP().equals(p))
    {
        throw new InvalidKeyException("DHPublicKey not for this KeyAgreement!");
    }

    if (lastPhase)
    {
        result = ((DHPublicKey)key).getY().modPow(x, p);
        return null;
    }
    else
    {
        result = ((DHPublicKey)key).getY().modPow(x, p);
    }

    return new JCEDHPublicKey(result, pubKey.getParams());
}
 
开发者ID:bullda,项目名称:DroidText,代码行数:34,代码来源:JCEDHKeyAgreement.java

示例10: 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 (DHPublicKeySpec)factory.getKeySpec
                                        (key, DHPublicKeySpec.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:coova,项目名称:jradius,代码行数:15,代码来源:DHCrypt.java

示例11: JCEDHPublicKey

import javax.crypto.interfaces.DHPublicKey; //导入方法依赖的package包/类
JCEDHPublicKey(
    DHPublicKey    key)
{
    this.y = key.getY();
    this.dhSpec = key.getParams();
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:7,代码来源:JCEDHPublicKey.java

示例12: BCDHPublicKey

import javax.crypto.interfaces.DHPublicKey; //导入方法依赖的package包/类
BCDHPublicKey(
    DHPublicKey key)
{
    this.y = key.getY();
    this.dhSpec = key.getParams();
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:7,代码来源:BCDHPublicKey.java


注:本文中的javax.crypto.interfaces.DHPublicKey.getParams方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。