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


Java DHGenParameterSpec类代码示例

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


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

示例1: engineInit

import javax.crypto.spec.DHGenParameterSpec; //导入依赖的package包/类
@Override
protected void engineInit(
    AlgorithmParameterSpec  genParamSpec,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec  spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:17,代码来源:JDKAlgorithmParameterGenerator.java

示例2: initialize

import javax.crypto.spec.DHGenParameterSpec; //导入依赖的package包/类
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
    throws InvalidAlgorithmParameterException
{
  HashMap attributes = new HashMap();
  if (params != null)
    {
      if (! (params instanceof DHGenParameterSpec) &&
          ! (params instanceof DHParameterSpec))
        throw new InvalidAlgorithmParameterException("params");

      attributes.put(GnuDHKeyPairGenerator.DH_PARAMETERS, params);
    }

  if (random != null)
    attributes.put(GnuDHKeyPairGenerator.SOURCE_OF_RANDOMNESS, random);

  attributes.put(GnuDHKeyPairGenerator.PREFERRED_ENCODING_FORMAT,
                 Integer.valueOf(Registry.ASN1_ENCODING_ID));
  adaptee.setup(attributes);
}
 
开发者ID:vilie,项目名称:javify,代码行数:21,代码来源:DHKeyPairGeneratorSpi.java

示例3: engineInit

import javax.crypto.spec.DHGenParameterSpec; //导入依赖的package包/类
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:16,代码来源:AlgorithmParameterGeneratorSpi.java

示例4: engineInit

import javax.crypto.spec.DHGenParameterSpec; //导入依赖的package包/类
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
protected void engineInit(AlgorithmParameterSpec genParamSpec,
                          SecureRandom random)
    throws InvalidAlgorithmParameterException {
    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    checkKeySize(primeSize);

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:DHParameterGenerator.java

示例5: engineInit

import javax.crypto.spec.DHGenParameterSpec; //导入依赖的package包/类
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
protected void engineInit(AlgorithmParameterSpec genParamSpec,
                          SecureRandom random)
    throws InvalidAlgorithmParameterException {
    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

    primeSize = dhParamSpec.getPrimeSize();

    // Re-uses DSA parameters and thus have the same range
    try {
        checkKeySize(primeSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    exponentSize = dhParamSpec.getExponentSize();
    if (exponentSize <= 0) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be greater than zero");
    }

    // Require exponentSize < primeSize
    if (exponentSize >= primeSize) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must be less than modulus size");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:43,代码来源:DHParameterGenerator.java

示例6: engineInit

import javax.crypto.spec.DHGenParameterSpec; //导入依赖的package包/类
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param genParamSpec the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
@Override
protected void engineInit(AlgorithmParameterSpec genParamSpec,
        SecureRandom random) throws InvalidAlgorithmParameterException {

    if (!(genParamSpec instanceof DHGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;
    primeSize = dhParamSpec.getPrimeSize();
    exponentSize = dhParamSpec.getExponentSize();
    if ((exponentSize <= 0) || (exponentSize >= primeSize)) {
        throw new InvalidAlgorithmParameterException(
                "Exponent size (" + exponentSize +
                ") must be positive and less than modulus size (" +
                primeSize + ")");
    }
    try {
        checkKeySize(primeSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    this.random = random;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:DHParameterGenerator.java

示例7: engineInit

import javax.crypto.spec.DHGenParameterSpec; //导入依赖的package包/类
protected void engineInit(
    AlgorithmParameterSpec  genParamSpec,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    if (!(genParamSpec instanceof DHGenParameterSpec))
    {
        throw new InvalidAlgorithmParameterException("DH parameter generator requires a DHGenParameterSpec for initialisation");
    }
    DHGenParameterSpec  spec = (DHGenParameterSpec)genParamSpec;

    this.strength = spec.getPrimeSize();
    this.l = spec.getExponentSize();
    this.random = random;
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:16,代码来源:JDKAlgorithmParameterGenerator.java

示例8: engineGetParameterSpec

import javax.crypto.spec.DHGenParameterSpec; //导入依赖的package包/类
protected AlgorithmParameterSpec engineGetParameterSpec(Class paramSpec)
    throws InvalidParameterSpecException
{
  if (paramSpec.isAssignableFrom(DHParameterSpec.class))
    return new DHParameterSpec(p, g, l);

  if (paramSpec.isAssignableFrom(DHGenParameterSpec.class))
    return new DHGenParameterSpec(p.bitLength(), l);

  throw new InvalidParameterSpecException("Wrong AlgorithmParameterSpec type: "
                                          + paramSpec.getName());
}
 
开发者ID:vilie,项目名称:javify,代码行数:13,代码来源:DHParameters.java

示例9: generateRandomParameter

import javax.crypto.spec.DHGenParameterSpec; //导入依赖的package包/类
public static DHParameterSpec generateRandomParameter(int primeSize, int keySize)
{
    try
    {
        AlgorithmParameterGenerator paramGen =
                AlgorithmParameterGenerator.getInstance(ALGORITHM);

        DHGenParameterSpec genParameterSpec =
                new DHGenParameterSpec(primeSize, keySize);

        paramGen.init(genParameterSpec);

        AlgorithmParameters params = paramGen.generateParameters();

        DHParameterSpec result = (DHParameterSpec)
                params.getParameterSpec(DHParameterSpec.class);

        if (DEBUG) _log.debug("Generated random DHParameterSpec, base: "
                + result.getG() + ", modulus: " + result.getP());

        return result;
    }
    catch (GeneralSecurityException e)
    {
        _log.error("Cannot generate DH params for primeSize: "
                + primeSize + " keySize: " + keySize, e);
        return null;
    }
}
 
开发者ID:jbufu,项目名称:openid4java,代码行数:30,代码来源:DiffieHellmanSession.java

示例10: testDHGenParameterSpec

import javax.crypto.spec.DHGenParameterSpec; //导入依赖的package包/类
/**
 * DHGenParameterSpec class testing. Tests the equivalence of
 * parameters specified in the constructor with the values returned
 * by getters.
 */
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "All functionality tested in one method. Probably it should be divided into several tests.",
        method = "DHGenParameterSpec",
        args = {int.class, int.class}
    ),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "All functionality tested in one method. Probably it should be divided into several tests.",
        method = "getExponentSize",
        args = {}
    ),
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "All functionality tested in one method. Probably it should be divided into several tests.",
        method = "getPrimeSize",
        args = {}
    )
})
public void testDHGenParameterSpec() {
    int[] primes = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    int[] exponents = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    for (int i=0; i<primes.length; i++) {
        DHGenParameterSpec ps = new DHGenParameterSpec(primes[i],
                                                        exponents[i]);
        assertEquals("The value returned by getPrimeSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), primes[i]);
        assertEquals("The value returned by getExponentSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), exponents[i]);
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:40,代码来源:DHGenParameterSpecTest.java

示例11: engineInit

import javax.crypto.spec.DHGenParameterSpec; //导入依赖的package包/类
/**
 * Initializes this parameter generator with a set of parameter
 * generation values, which specify the size of the prime modulus and
 * the size of the random exponent, both in bits.
 *
 * @param params the set of parameter generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
protected void engineInit(AlgorithmParameterSpec genParamSpec,
                          SecureRandom random)
    throws InvalidAlgorithmParameterException {
        if (!(genParamSpec instanceof DHGenParameterSpec)) {
            throw new InvalidAlgorithmParameterException
                ("Inappropriate parameter type");
        }

        DHGenParameterSpec dhParamSpec = (DHGenParameterSpec)genParamSpec;

        primeSize = dhParamSpec.getPrimeSize();
        if ((primeSize<512) || (primeSize>1024) || (primeSize%64 != 0)) {
            throw new InvalidAlgorithmParameterException
                ("Modulus size must be multiple of 64, and can only range "
                 + "from 512 to 1024 (inclusive)");
        }

        exponentSize = dhParamSpec.getExponentSize();
        if (exponentSize <= 0) {
            throw new InvalidAlgorithmParameterException
                ("Exponent size must be greater than zero");
        }

        // Require exponentSize < primeSize
        if (exponentSize >= primeSize) {
            throw new InvalidAlgorithmParameterException
                ("Exponent size must be less than modulus size");
        }
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:41,代码来源:DHParameterGenerator.java

示例12: testDHGenParameterSpec

import javax.crypto.spec.DHGenParameterSpec; //导入依赖的package包/类
/**
 * DHGenParameterSpec class testing. Tests the equivalence of
 * parameters specified in the constructor with the values returned
 * by getters.
 */
public void testDHGenParameterSpec() {
    int[] primes = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    int[] exponents = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    for (int i=0; i<primes.length; i++) {
        DHGenParameterSpec ps = new DHGenParameterSpec(primes[i],
                                                        exponents[i]);
        assertEquals("The value returned by getPrimeSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), primes[i]);
        assertEquals("The value returned by getExponentSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), exponents[i]);
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:DHGenParameterSpecTest.java


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