當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。