• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java AlgorithmParameterGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: generateParameterSpec

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
protected AlgorithmParameterSpec generateParameterSpec(ASN1ObjectIdentifier macOID, SecretKey encKey)
    throws CMSException
{
    try
    {
        if (macOID.equals(PKCSObjectIdentifiers.RC2_CBC))
        {
            byte[] iv = new byte[8];

            random.nextBytes(iv);

            return new RC2ParameterSpec(encKey.getEncoded().length * 8, iv);
        }

        AlgorithmParameterGenerator pGen = helper.createAlgorithmParameterGenerator(macOID);

        AlgorithmParameters p = pGen.generateParameters();

        return p.getParameterSpec(IvParameterSpec.class);
    }
    catch (GeneralSecurityException e)
    {
        return null;
    }
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:26,代码来源:JceCMSMacCalculatorBuilder.java


示例2: createAlgorithmParameterGenerator

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
AlgorithmParameterGenerator createAlgorithmParameterGenerator(ASN1ObjectIdentifier algorithm)
    throws GeneralSecurityException
{
    String algorithmName = (String)BASE_CIPHER_NAMES.get(algorithm);

    if (algorithmName != null)
    {
        try
        {
            // this is reversed as the Sun policy files now allow unlimited strength RSA
            return helper.createAlgorithmParameterGenerator(algorithmName);
        }
        catch (NoSuchAlgorithmException e)
        {
            // Ignore
        }
    }
    return helper.createAlgorithmParameterGenerator(algorithm.getId());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:CRMFHelper.java


示例3: testDSAGenParameterSpec

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
private static void testDSAGenParameterSpec(DataTuple dataTuple)
        throws NoSuchAlgorithmException, NoSuchProviderException,
        InvalidParameterSpecException, InvalidAlgorithmParameterException {
    System.out.printf("Test case: primePLen=%d, " + "subprimeQLen=%d%n",
            dataTuple.primePLen, dataTuple.subprimeQLen);

    AlgorithmParameterGenerator apg
            = AlgorithmParameterGenerator.getInstance(ALGORITHM_NAME,
                    PROVIDER_NAME);

    DSAGenParameterSpec genParamSpec = createGenParameterSpec(dataTuple);
    // genParamSpec will be null if IllegalAE is thrown when expected.
    if (genParamSpec == null) {
        return;
    }

    try {
        apg.init(genParamSpec, null);
        AlgorithmParameters param = apg.generateParameters();

        checkParam(param, genParamSpec);
        System.out.println("Test case passed");
    } catch (InvalidParameterException ipe) {
        throw new RuntimeException("Test case failed.", ipe);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:TestDSAGenParameterSpec.java


示例4: testDSAGenParameterSpec

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
private static void testDSAGenParameterSpec(DataTuple dataTuple)
        throws NoSuchAlgorithmException, NoSuchProviderException,
        InvalidParameterSpecException, InvalidAlgorithmParameterException {
    System.out.printf("Test case: primePLen=%d, " + "subprimeQLen=%d%n",
            dataTuple.primePLen, dataTuple.subprimeQLen);

    AlgorithmParameterGenerator apg =
            AlgorithmParameterGenerator.getInstance(ALGORITHM_NAME,
                    PROVIDER_NAME);

    DSAGenParameterSpec genParamSpec = createGenParameterSpec(dataTuple);
    // genParamSpec will be null if IllegalAE is thrown when expected.
    if (genParamSpec == null) {
        return;
    }

    try {
        apg.init(genParamSpec, null);
        AlgorithmParameters param = apg.generateParameters();

        checkParam(param, genParamSpec);
        System.out.println("Test case passed");
    } catch (InvalidParameterException ipe) {
        throw new RuntimeException("Test case failed.", ipe);
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:27,代码来源:TestDSAGenParameterSpec.java


示例5: testDefaultTagSizeAlgorithmParameterGenerator

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
/**
 * The default authentication tag size should be 128-bit by default for the following reasons:
 * <br>
 * (1) Security: Ferguson, N., Authentication Weaknesses in GCM, Natl. Inst. Stand. Technol. [Web
 * page], http://www.csrc.nist.gov/groups/ST/toolkit/BCM/documents/comments/
 * CWC-GCM/Ferguson2.pdf, May 20, 2005. This paper points out that a n-bit tag has lower strength
 * than expected. <br>
 * (2) Compatibility: Assume an implementer tests some code using one provider than switches to
 * another provider. Such a switch should ideally not lower the security. <br>
 * BouncyCastle used to have only 12-byte authentication tag (b/26186727).
 */
@Test
public void testDefaultTagSizeAlgorithmParameterGenerator() throws Exception {
  byte[] input = new byte[10];
  byte[] key = new byte[16];
  Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
  try {
    AlgorithmParameterGenerator.getInstance("GCM");
  } catch (NoSuchAlgorithmException ex) {
    // Conscrypt does not support AlgorithmParameterGenerator for GCM.
    System.out.println("testDefaultTagSizeAlgorithmParameterGenerator:" + ex.toString());
    return;
  }
  AlgorithmParameters param = AlgorithmParameterGenerator.getInstance("GCM").generateParameters();
  cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "AES"), param);
  byte[] output = cipher.doFinal(input);
  assertEquals(input.length + 16, output.length);
}
 
开发者ID:google,项目名称:wycheproof,代码行数:29,代码来源:AesGcmTest.java


示例6: DHExchange

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
/**
 * Use 1536 for Fast Prime Generation (less secure) or 2048 for slow prime generation (secure)
 * @param strength
 * @throws InvalidKeyException
 * @throws IllegalStateException
 * @throws InvalidAlgorithmParameterException
 * @throws NoSuchAlgorithmException
 * @throws NoSuchProviderException
 * @throws InvalidKeySpecException
 * @throws InvalidParameterSpecException
 */
public DHExchange(int strength) throws InvalidKeyException, IllegalStateException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException, InvalidParameterSpecException {
	Security.addProvider(new org.spongycastle.jce.provider.BouncyCastleProvider());
	
	AlgorithmParameterGenerator paramGen = AlgorithmParameterGenerator.getInstance("DH", "SC");
	paramGen.init(strength); // number of bits
	AlgorithmParameters params = paramGen.generateParameters();
	DHParameterSpec dhSpec = (DHParameterSpec)params.getParameterSpec(DHParameterSpec.class);

	BigInteger p = dhSpec.getP();
	BigInteger g = dhSpec.getG();
	
    DHParameterSpec dhParams = new DHParameterSpec(p, g);
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH", "SC");
    keyGen.initialize(dhParams, new SecureRandom());
    KeyAgreement aKeyAgree = KeyAgreement.getInstance("DH", "SC");
    KeyPair aPair = keyGen.generateKeyPair();
    KeyAgreement bKeyAgree = KeyAgreement.getInstance("DH", "SC");
    KeyPair bPair = keyGen.generateKeyPair();

    aKeyAgree.init(aPair.getPrivate());
    bKeyAgree.init(bPair.getPrivate());
    
    aKeyAgree.doPhase(bPair.getPublic(), true);
    bKeyAgree.doPhase(aPair.getPublic(), true);
}
 
开发者ID:manuelsc,项目名称:Raven-Messenger,代码行数:37,代码来源:DHExchange.java


示例7: createAPGen

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
protected AlgorithmParameterGenerator[] createAPGen() {
    if (!DSASupported) {
        fail(validAlgName + " algorithm is not supported");
        return null;
    }
    AlgorithmParameterGenerator[] apg = new AlgorithmParameterGenerator[3];
    try {
        apg[0] = AlgorithmParameterGenerator.getInstance(validAlgName);
        apg[1] = AlgorithmParameterGenerator.getInstance(validAlgName,
                validProvider);
        apg[2] = AlgorithmParameterGenerator.getInstance(validAlgName,
                validProviderName);
        return apg;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:19,代码来源:AlgorithmParameterGenerator1Test.java


示例8: testAlgorithmParameterGenerator02

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
/**
 * Test for <code>getInstance(String algorithm)</code> method
 * Assertion: returns AlgorithmParameterGenerator instance
 * when algorithm is DSA
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "getInstance",
    args = {java.lang.String.class}
)
public void testAlgorithmParameterGenerator02()
        throws NoSuchAlgorithmException {
    if (!DSASupported) {
        fail(validAlgName + " algorithm is not supported");
        return;
    }
    AlgorithmParameterGenerator apg;
    for (int i = 0; i < algs.length; i++) {
        apg = AlgorithmParameterGenerator.getInstance(algs[i]);
        assertEquals("Incorrect algorithm", apg.getAlgorithm(), algs[i]);
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:24,代码来源:AlgorithmParameterGenerator1Test.java


示例9: testAlgorithmParameterGenerator04

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
/**
 * Test for <code>getInstance(String algorithm, String provider)</code>
 * method
 * Assertion: throws NoSuchProviderException if provider is not
 * available
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "getInstance",
    args = {java.lang.String.class, java.lang.String.class}
)
public void testAlgorithmParameterGenerator04()
        throws NoSuchAlgorithmException {
    if (!DSASupported) {
        fail(validAlgName + " algorithm is not supported");
        return;
    }
    for (int i = 0; i < algs.length; i++) {
        for (int j = 1; j < invalidValues.length; j++) {
            try {
                AlgorithmParameterGenerator.getInstance(algs[i],
                        invalidValues[j]);
                fail("NoSuchProviderException must be thrown (provider: "
                        .concat(invalidValues[j]));
            } catch (NoSuchProviderException e) {
            }
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:31,代码来源:AlgorithmParameterGenerator1Test.java


示例10: testAlgorithmParameterGenerator06

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
/**
 * Test for <code>getInstance(String algorithm, String provider)</code>
 * method
 * Assertion: return AlgorithmParameterGenerator
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "getInstance",
    args = {java.lang.String.class, java.lang.String.class}
)
public void testAlgorithmParameterGenerator06()
        throws NoSuchAlgorithmException, NoSuchProviderException {
    if (!DSASupported) {
        fail(validAlgName + " algorithm is not supported");
        return;
    }
    AlgorithmParameterGenerator apg;
    for (int i = 0; i < algs.length; i++) {
        apg = AlgorithmParameterGenerator.getInstance(algs[i],
                validProviderName);
        assertEquals("Incorrect algorithm", algs[i], apg.getAlgorithm());
        assertEquals("Incorrect provider", apg.getProvider().getName(),
                validProviderName);
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:27,代码来源:AlgorithmParameterGenerator1Test.java


示例11: testAlgorithmParameterGenerator07

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
/**
 * Test for <code>getInstance(String algorithm, Provider provider)</code>
 * method
 * Assertion: throws IllegalArgumentException when provider is null
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "getInstance",
    args = {java.lang.String.class, java.security.Provider.class}
)
public void testAlgorithmParameterGenerator07()
        throws NoSuchAlgorithmException {
    if (!DSASupported) {
        fail(validAlgName + " algorithm is not supported");
        return;
    }
    Provider provider = null;
    for (int i = 0; i < algs.length; i++) {
        try {
            AlgorithmParameterGenerator.getInstance(algs[i], provider);
            fail("IllegalArgumentException must be thrown when provider is null");
        } catch (IllegalArgumentException e) {
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:27,代码来源:AlgorithmParameterGenerator1Test.java


示例12: testAlgorithmParameterGenerator09

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
/**
 * Test for <code>getInstance(String algorithm, Provider provider)</code>
 * method
 * Assertion: returns AlgorithmParameterGenerator object
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "",
    method = "getInstance",
    args = {java.lang.String.class, java.security.Provider.class}
)
public void testAlgorithmParameterGenerator09()
        throws NoSuchAlgorithmException {
    if (!DSASupported) {
        fail(validAlgName + " algorithm is not supported");
        return;
    }
    AlgorithmParameterGenerator apg;
    for (int i = 0; i < algs.length; i++) {
        apg = AlgorithmParameterGenerator.getInstance(algs[i],
                validProvider);
        assertEquals("Incorrect algorithm", apg.getAlgorithm(), algs[i]);
        assertEquals("Incorrect provider", apg.getProvider(), validProvider);
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:26,代码来源:AlgorithmParameterGenerator1Test.java


示例13: testAlgorithmParameterGenerator10

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
/**
 * Test for <code>generateParameters()</code> method
 * Assertion: returns AlgorithmParameters object
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "generateParameters",
    args = {}
)
public void testAlgorithmParameterGenerator10()
        throws NoSuchAlgorithmException {
    if (!DSASupported) {
        fail(validAlgName + " algorithm is not supported");
        return;
    }
    AlgorithmParameterGenerator apg = AlgorithmParameterGenerator
            .getInstance(validAlgName);
    apg.init(512);
    AlgorithmParameters ap = apg.generateParameters();
    assertEquals("Incorrect algorithm", ap.getAlgorithm().toUpperCase(),
            apg.getAlgorithm().toUpperCase());
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:24,代码来源:AlgorithmParameterGenerator1Test.java


示例14: test

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
@Override
public void test() throws Exception {
    AlgorithmParameterGenerator apg = AlgorithmParameterGenerator.getInstance("DH");
    apg.init(1024, new SecureRandom());
    AlgorithmParameters ap = apg.generateParameters();
    DHParameterSpec ps = ap.getParameterSpec(DHParameterSpec.class);

    KeyAgreementGen kag1 = new KeyAgreementGen(ps);
    KeyAgreementGen kag2 = new KeyAgreementGen(ps);

    byte[] bArray1 = kag1.getPublicKeyBytes();
    byte[] bArray2 = kag2.getPublicKeyBytes();

    byte[] sk1 = kag1.getSecretKey(algName, bArray2);
    byte[] sk2 = kag2.getSecretKey(algName, bArray1);

    if (Arrays.areEqual(sk1, sk2) == false) {
        throw new Exception ("Generated keys are not the same");
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:21,代码来源:KeyAgreementThread.java


示例15: testDHGen

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
@TestTargetNew(
    level = TestLevel.ADDITIONAL,
    method = "method",
    args = {}
)
@BrokenTest("Suffers from DH slowness, disabling for now")
public void testDHGen() throws Exception {
    KeyPairGenerator gen = null;
    try {
        gen = KeyPairGenerator.getInstance("DH");
    } catch (NoSuchAlgorithmException e) {
        fail(e.getMessage());
    }

    AlgorithmParameterGenerator algorithmparametergenerator = AlgorithmParameterGenerator.getInstance("DH");
    algorithmparametergenerator.init(1024, new SecureRandom());
    AlgorithmParameters algorithmparameters = algorithmparametergenerator.generateParameters();
    DHParameterSpec dhparameterspec = algorithmparameters.getParameterSpec(DHParameterSpec.class);


    //gen.initialize(1024);
    gen.initialize(dhparameterspec);
    KeyPair key = gen.generateKeyPair();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:25,代码来源:OldDHTest.java


示例16: test_initI

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
public void test_initI() throws Exception {
    // Test for method void
    // java.security.AlgorithmParameterGenerator.init(int)
        // checks that no exception is thrown
    int[] valid = {512, 576, 640, 960, 1024};
    AlgorithmParameterGenerator gen = AlgorithmParameterGenerator
            .getInstance("DSA");

    for (int i = 0; i < valid.length; i++) {
        try {
            gen.init(valid[i]);
        } catch (Exception e) {
            fail("Exception should not be thrown for valid parameter" + valid[i]);
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:17,代码来源:OldAlgorithmParameterGeneratorTest.java


示例17: test_initILjava_security_SecureRandom

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
public void test_initILjava_security_SecureRandom() throws Exception {
    // Test for method void
    // java.security.AlgorithmParameterGenerator.init(int,
    // java.security.SecureRandom)
        // checks that no exception is thrown
    int[] valid = {512, 576, 640, 960, 1024};
    AlgorithmParameterGenerator gen = AlgorithmParameterGenerator
            .getInstance("DSA");

    for (int i = 0; i < valid.length; i++) {
        try {
            gen.init(valid[i], new SecureRandom());
            gen.init(valid[i], null);
        } catch (Exception e) {
            fail("Exception should not be thrown for valid parameter" + valid[i]);
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:19,代码来源:OldAlgorithmParameterGeneratorTest.java


示例18: test_initLjava_security_spec_AlgorithmParameterSpec

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
/**
 * @tests java.security.AlgorithmParameterGenerator#init(java.security.spec.AlgorithmParameterSpec)
 */
public void test_initLjava_security_spec_AlgorithmParameterSpec() throws Exception {
       // Test for method void
       // java.security.AlgorithmParameterGenerator.init(java.security.spec.AlgorithmParameterSpec)
       // checks that InvalidAlgorithmParameterException is thrown
       DSAParameterSpec spec = new DSAParameterSpec(BigInteger.ONE,
               BigInteger.ONE, BigInteger.ONE);
       AlgorithmParameterGenerator gen = AlgorithmParameterGenerator
               .getInstance("DSA");
       try {
           gen.init(spec);
           fail("No expected InvalidAlgorithmParameterException");
       } catch (InvalidAlgorithmParameterException e) {
           //expected
       }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:19,代码来源:AlgorithmParameterGenerator3Test.java


示例19: test_initLjava_security_spec_AlgorithmParameterSpecLjava_security_SecureRandom

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
/**
 * @tests java.security.AlgorithmParameterGenerator#init(java.security.spec.AlgorithmParameterSpec,
 *        java.security.SecureRandom)
 */
public void test_initLjava_security_spec_AlgorithmParameterSpecLjava_security_SecureRandom() throws Exception {
       // Test for method void
       // java.security.AlgorithmParameterGenerator.init(java.security.spec.AlgorithmParameterSpec,
       // java.security.SecureRandom)
       // checks that InvalidAlgorithmParameterException  is thrown
       DSAParameterSpec spec = new DSAParameterSpec(BigInteger.ONE,
               BigInteger.ONE, BigInteger.ONE);
       AlgorithmParameterGenerator gen = AlgorithmParameterGenerator
               .getInstance("DSA");
       try {
           gen.init(spec, new SecureRandom());
           fail("No expected InvalidAlgorithmParameterException");
       } catch (InvalidAlgorithmParameterException e) {
           //expected
       }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:AlgorithmParameterGenerator3Test.java


示例20: testRandom

import java.security.AlgorithmParameterGenerator; //导入依赖的package包/类
private void testRandom(
    int         size)
    throws Exception
{
    AlgorithmParameterGenerator a = AlgorithmParameterGenerator.getInstance("DH", "BC");
    a.init(size, new SecureRandom());
    AlgorithmParameters params = a.generateParameters();

    byte[] encodeParams = params.getEncoded();

    AlgorithmParameters a2 = AlgorithmParameters.getInstance("DH", "BC");
    a2.init(encodeParams);

    // a and a2 should be equivalent!
    byte[] encodeParams_2 = a2.getEncoded();

    if (!areEqual(encodeParams, encodeParams_2))
    {
        fail("encode/decode parameters failed");
    }

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

    testGP("DH", size, 0, dhP.getG(), dhP.getP());
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:26,代码来源:DHTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DefaultMBeanServerInterceptor类代码示例发布时间:2022-05-21
下一篇:
Java IContentProposal类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap