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


Java DHParameterSpec类代码示例

本文整理汇总了Java中javax.crypto.spec.DHParameterSpec的典型用法代码示例。如果您正苦于以下问题:Java DHParameterSpec类的具体用法?Java DHParameterSpec怎么用?Java DHParameterSpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testDh

import javax.crypto.spec.DHParameterSpec; //导入依赖的package包/类
/** Check that key agreement using DH works. */
@SuppressWarnings("InsecureCryptoUsage")
@Test
public void testDh() throws Exception {
  KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH");
  DHParameterSpec dhparams = ike2048();
  keyGen.initialize(dhparams);
  KeyPair keyPairA = keyGen.generateKeyPair();
  KeyPair keyPairB = keyGen.generateKeyPair();

  KeyAgreement kaA = KeyAgreement.getInstance("DH");
  KeyAgreement kaB = KeyAgreement.getInstance("DH");
  kaA.init(keyPairA.getPrivate());
  kaB.init(keyPairB.getPrivate());
  kaA.doPhase(keyPairB.getPublic(), true);
  kaB.doPhase(keyPairA.getPublic(), true);
  byte[] kAB = kaA.generateSecret();
  byte[] kBA = kaB.generateSecret();
  assertEquals(TestUtil.bytesToHex(kAB), TestUtil.bytesToHex(kBA));
}
 
开发者ID:google,项目名称:wycheproof,代码行数:21,代码来源:DhTest.java

示例2: initialize

import javax.crypto.spec.DHParameterSpec; //导入依赖的package包/类
public void initialize(
    AlgorithmParameterSpec params,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(params instanceof DHParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("parameter object not a DHParameterSpec");
    }
    DHParameterSpec dhParams = (DHParameterSpec)params;

    param = new DHKeyGenerationParameters(random, new DHParameters(dhParams.getP(), dhParams.getG(), null, dhParams.getL()));

    engine.init(param);
    initialised = true;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:17,代码来源:KeyPairGeneratorSpi.java

示例3: engineInit

import javax.crypto.spec.DHParameterSpec; //导入依赖的package包/类
protected void engineInit(
    AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException
{
    if (!(paramSpec instanceof ElGamalParameterSpec) && !(paramSpec instanceof DHParameterSpec))
    {
        throw new InvalidParameterSpecException("DHParameterSpec required to initialise a ElGamal algorithm parameters object");
    }

    if (paramSpec instanceof ElGamalParameterSpec)
    {
        this.currentSpec = (ElGamalParameterSpec)paramSpec;
    }
    else
    {
        DHParameterSpec s = (DHParameterSpec)paramSpec;

        this.currentSpec = new ElGamalParameterSpec(s.getP(), s.getG());
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:21,代码来源:AlgorithmParametersSpi.java

示例4: getDHParameterSpec

import javax.crypto.spec.DHParameterSpec; //导入依赖的package包/类
/**
 * Return DH parameters for the given keylength. Uses cache if possible,
 * generates new parameters and adds them to the cache otherwise.
 */
public static DHParameterSpec getDHParameterSpec(int keyLength,
        SecureRandom random)
        throws NoSuchAlgorithmException, InvalidParameterSpecException {
    DHParameterSpec spec = getCachedDHParameterSpec(keyLength);
    if (spec != null) {
        return spec;
    }
    AlgorithmParameterGenerator gen =
            AlgorithmParameterGenerator.getInstance("DH");
    gen.init(keyLength, random);
    AlgorithmParameters params = gen.generateParameters();
    spec = params.getParameterSpec(DHParameterSpec.class);
    dhCache.put(Integer.valueOf(keyLength), spec);
    return spec;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:ParameterCache.java

示例5: initDHKeys

import javax.crypto.spec.DHParameterSpec; //导入依赖的package包/类
/**
 * Initialize the Diffie-Hellman keys. This method is not thread safe
 */
private void initDHKeys(DistributionConfig config) throws Exception {

  dhSKAlgo = config.getSecurityUDPDHAlgo();
  // Initialize the keys when either the host is a peer that has
  // non-blank setting for DH symmetric algo, or this is a server
  // that has authenticator defined.
  if ((dhSKAlgo != null && dhSKAlgo.length() > 0)) {
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH");
    DHParameterSpec dhSpec = new DHParameterSpec(dhP, dhG, dhL);
    keyGen.initialize(dhSpec);
    KeyPair keypair = keyGen.generateKeyPair();

    // Get the generated public and private keys
    dhPrivateKey = keypair.getPrivate();
    dhPublicKey = keypair.getPublic();
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:21,代码来源:GMSEncrypt.java

示例6: testKeyPairGeneratorDhInitializeWithParamSpec

import javax.crypto.spec.DHParameterSpec; //导入依赖的package包/类
@Test
public void testKeyPairGeneratorDhInitializeWithParamSpec()
    throws NoSuchProviderException, NoSuchAlgorithmException,
           InvalidAlgorithmParameterException {

    int testDHKeySizes[] = { 512, 1024, 2048 };

    for (int i = 0; i < testDHKeySizes.length; i++) {

        KeyPairGenerator kpg =
            KeyPairGenerator.getInstance("DH", "wolfJCE");

        DHParameterSpec spec = new DHParameterSpec(
                new BigInteger(prime),
                new BigInteger(base),
                testDHKeySizes[i]);

        kpg.initialize(spec);
        KeyPair pair = kpg.generateKeyPair();
    }
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:22,代码来源:WolfCryptKeyPairGeneratorTest.java

示例7: testKeyPairGeneratorDhMultipleKeyGen

import javax.crypto.spec.DHParameterSpec; //导入依赖的package包/类
@Test
public void testKeyPairGeneratorDhMultipleKeyGen()
    throws NoSuchProviderException, NoSuchAlgorithmException,
           InvalidAlgorithmParameterException {

    KeyPairGenerator kpg =
        KeyPairGenerator.getInstance("DH", "wolfJCE");

    DHParameterSpec spec = new DHParameterSpec(
            new BigInteger(prime), new BigInteger(base), 512);

    kpg.initialize(spec);

    KeyPair kp1 = kpg.generateKeyPair();
    KeyPair kp2 = kpg.generateKeyPair();
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:17,代码来源:WolfCryptKeyPairGeneratorTest.java

示例8: initialize

import javax.crypto.spec.DHParameterSpec; //导入依赖的package包/类
/**
 * Initializes this key pair generator for the specified parameter
 * set and source of randomness.
 *
 * <p>The given parameter set contains the prime modulus, the base
 * generator, and optionally the requested size in bits of the random
 * exponent (private value).
 *
 * @param params the parameter set used to generate the key pair
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameters
 * are inappropriate for this key pair generator
 */
public void initialize(AlgorithmParameterSpec algParams,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(algParams instanceof DHParameterSpec)){
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    params = (DHParameterSpec)algParams;
    pSize = params.getP().bitLength();
    try {
        checkKeySize(pSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    // exponent size is optional, could be 0
    lSize = params.getL();

    // Require exponentSize < primeSize
    if ((lSize != 0) && (lSize > pSize)) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must not be larger than modulus size");
    }
    this.random = random;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:40,代码来源:DHKeyPairGenerator.java

示例9: getFFDHEDHParameterSpec

import javax.crypto.spec.DHParameterSpec; //导入依赖的package包/类
private static DHParameterSpec getFFDHEDHParameterSpec(
        NamedGroup namedGroup) {
    DHParameterSpec spec = null;
    switch (namedGroup) {
        case FFDHE_2048:
            spec = PredefinedDHParameterSpecs.ffdheParams.get(2048);
            break;
        case FFDHE_3072:
            spec = PredefinedDHParameterSpecs.ffdheParams.get(3072);
            break;
        case FFDHE_4096:
            spec = PredefinedDHParameterSpecs.ffdheParams.get(4096);
            break;
        case FFDHE_6144:
            spec = PredefinedDHParameterSpecs.ffdheParams.get(6144);
            break;
        case FFDHE_8192:
            spec = PredefinedDHParameterSpecs.ffdheParams.get(8192);
    }

    return spec;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:SupportedGroupsExtension.java

示例10: getPredefinedDHParameterSpec

import javax.crypto.spec.DHParameterSpec; //导入依赖的package包/类
private static DHParameterSpec getPredefinedDHParameterSpec(
        NamedGroup namedGroup) {
    DHParameterSpec spec = null;
    switch (namedGroup) {
        case FFDHE_2048:
            spec = PredefinedDHParameterSpecs.definedParams.get(2048);
            break;
        case FFDHE_3072:
            spec = PredefinedDHParameterSpecs.definedParams.get(3072);
            break;
        case FFDHE_4096:
            spec = PredefinedDHParameterSpecs.definedParams.get(4096);
            break;
        case FFDHE_6144:
            spec = PredefinedDHParameterSpecs.definedParams.get(6144);
            break;
        case FFDHE_8192:
            spec = PredefinedDHParameterSpecs.definedParams.get(8192);
    }

    return spec;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:SupportedGroupsExtension.java

示例11: initialize

import javax.crypto.spec.DHParameterSpec; //导入依赖的package包/类
/**
 * Initializes this key pair generator for the specified parameter
 * set and source of randomness.
 *
 * <p>The given parameter set contains the prime modulus, the base
 * generator, and optionally the requested size in bits of the random
 * exponent (private value).
 *
 * @param algParams the parameter set used to generate the key pair
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameters
 * are inappropriate for this key pair generator
 */
public void initialize(AlgorithmParameterSpec algParams,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(algParams instanceof DHParameterSpec)){
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    params = (DHParameterSpec)algParams;
    pSize = params.getP().bitLength();
    try {
        checkKeySize(pSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    // exponent size is optional, could be 0
    lSize = params.getL();

    // Require exponentSize < primeSize
    if ((lSize != 0) && (lSize > pSize)) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must not be larger than modulus size");
    }
    this.random = random;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:DHKeyPairGenerator.java

示例12: main

import javax.crypto.spec.DHParameterSpec; //导入依赖的package包/类
@Override
public void main(Provider provider) throws Exception {
    if (provider.getService("KeyPairGenerator", "DiffieHellman") == null) {
        System.out.println("No support of DH KeyPairGenerator, skipping");
        return;
    }

    for (SupportedKeySize keySize : SupportedKeySize.values()) {
        System.out.println("Checking " + keySize.primeSize + " ...");
        KeyPairGenerator kpg =
                KeyPairGenerator.getInstance("DiffieHellman", provider);
        kpg.initialize(keySize.primeSize);
        KeyPair kp = kpg.generateKeyPair();
        checkKeyPair(kp, keySize.primeSize, provider);

        DHPublicKey publicKey = (DHPublicKey)kp.getPublic();
        BigInteger p = publicKey.getParams().getP();
        BigInteger g = publicKey.getParams().getG();
        kpg.initialize(new DHParameterSpec(p, g));
        kp = kpg.generateKeyPair();
        checkKeyPair(kp, keySize.primeSize, provider);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:SupportedDHKeys.java

示例13: getValueLinkPublicKey

import javax.crypto.spec.DHParameterSpec; //导入依赖的package包/类
/**
 * Get a public key object for the ValueLink supplied public key
 * @return PublicKey object of ValueLinks's public key
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeySpecException
 */
public PublicKey getValueLinkPublicKey() throws NoSuchAlgorithmException, InvalidKeySpecException {
    // read the valuelink public key
    String publicValue = (String) props.get("payment.valuelink.publicValue");
    byte[] publicKeyBytes = StringUtil.fromHexString(publicValue);

    // initialize the parameter spec
    DHParameterSpec dhParamSpec = this.getDHParameterSpec();

    // load the valuelink public key
    KeyFactory keyFactory = KeyFactory.getInstance("DH");
    BigInteger publicKeyInt = new BigInteger(publicKeyBytes);
    DHPublicKeySpec dhPublicSpec = new DHPublicKeySpec(publicKeyInt, dhParamSpec.getP(), dhParamSpec.getG());
    PublicKey vlPublic = keyFactory.generatePublic(dhPublicSpec);

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

示例14: generateECKeys

import javax.crypto.spec.DHParameterSpec; //导入依赖的package包/类
public static KeyPair generateECKeys() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    /* The factors were self-generated [@CapacitorSet]. Source:
    import java.security.AlgorithmParameterGenerator;
    import java.security.AlgorithmParameters;
    import javax.crypto.spec.DHParameterSpec;
    public class Main {
      public static void main(String[] argv) throws Exception {
        AlgorithmParameterGenerator paramGen = AlgorithmParameterGenerator.getInstance("DH");
        paramGen.init(2048);
        AlgorithmParameters params = paramGen.generateParameters();
        DHParameterSpec dhSpec = params.getParameterSpec(DHParameterSpec.class);
        System.out.println(dhSpec.getG().toString(16));
        System.out.println(dhSpec.getP().toString(16));
      }
    } */
    BigInteger g = new BigInteger(
            "93445990947cef561f52de0fa07a232b07ba78c6d1b3a09d1b838de4d3c51f843c307427b963b2060fb30d8088e5bc8459cf4201987e5d83c2a9c2b72cee53f7905c92c6425f9f97df71b8c09ea97e8435c30b57d6e84bb134af3aeaacf4047da02716c0b85c1b403dba306569aaaa6fb7b01861c4f692af24ad89f02408762380dbdd7186e36d59edf9d2abd93bfe8f04e4e20a214df66dabd02d1b15e6b943ad73a5695110286d6e3b4d35f8f08ece05728645bfb85d29ec561d6db16ac4bb5f58805eea1298b29161f74bac3ff9003dabfcc5fdc7604fb7bfdbf96e9c6c8ca7b357a74a94f62752a780a451bed793400b56a1a9414fa38458ed797896ca8c",
            16);
    BigInteger p = new BigInteger(
            "ab0eab856a13bdc2c35ae735b04b6424f7c8d33beae9f7d28ff58f84a845e727a2cb3d3fcf716ff839e65fbeaa4f9b38eddd3b87c03b1bf4e5dd86f211a7845d67d2a44a64b5126776fc5a210196020e6552930fbb5f98f5f23589d51dee3fbdb9e714989ad966465ee56e3551b216f0e15c257c0aeddbc1e6b394341a4c07a5412e22cda2c052d232ea68c9709d4e1fe359780a9842f7b30130a7bea563c31897e95cc7cff834ac46aa4d56a1f75b5437dd444d7be4e33c069c340020250c713d6219c5b62d252ad348220254ff77cd6ba54cdd0f37ec6d6cc9bd22ea6794b6237f6fb056edfd7132d4a1be3ddc7cfe6fe57b974d5a9d67ac7059cab02b2a7b",
            16);
    final DHParameterSpec dhSpec = new DHParameterSpec(p, g, 511);
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH");
    keyGen.initialize(dhSpec);
    return keyGen.generateKeyPair();
}
 
开发者ID:Ichicoro,项目名称:privacylayer,代码行数:27,代码来源:AESPlatform.java

示例15: ike2048

import javax.crypto.spec.DHParameterSpec; //导入依赖的package包/类
public DHParameterSpec ike2048() {
  final BigInteger p =
      new BigInteger(
          "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1"
              + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD"
              + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245"
              + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED"
              + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D"
              + "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F"
              + "83655D23DCA3AD961C62F356208552BB9ED529077096966D"
              + "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B"
              + "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9"
              + "DE2BCBF6955817183995497CEA956AE515D2261898FA0510"
              + "15728E5A8AACAA68FFFFFFFFFFFFFFFF",
          16);
  final BigInteger g = new BigInteger("2");
  return new DHParameterSpec(p, g);
}
 
开发者ID:google,项目名称:wycheproof,代码行数:19,代码来源:DhiesTest.java


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