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


Java AlgorithmParameterGenerator.generateParameters方法代码示例

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


在下文中一共展示了AlgorithmParameterGenerator.generateParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例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:campolake,项目名称:openjdk9,代码行数:27,代码来源:TestDSAGenParameterSpec.java

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

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

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

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

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

示例9: testRandom

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

    byte[] encodeParams = params.getEncoded();

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

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

    if (!areEqual(encodeParams, encodeParams_2))
    {
        fail(this.getName() + ": encode/decode parameters failed");
    }

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

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

示例10: generateParameterSpec

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

            rand.nextBytes(iv);

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

        AlgorithmParameterGenerator pGen = CMSEnvelopedHelper.INSTANCE.createAlgorithmParameterGenerator(encryptionOID, encProvider);

        AlgorithmParameters p = pGen.generateParameters();

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

示例11: 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) {
        // The DSAGenParameterSpec API support this, but the real
        // implementation in SUN doesn't
        if (!dataTuple.isSunProviderSupported) {
            System.out.println("Test case passed: expected "
                    + "InvalidParameterException is caught");
        } else {
            throw new RuntimeException("Test case failed.", ipe);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:34,代码来源:TestDSAGenParameterSpec.java

示例12: createDERForRecipient

import java.security.AlgorithmParameterGenerator; //导入方法依赖的package包/类
private ASN1Primitive createDERForRecipient(byte[] in, X509Certificate cert) 
    throws IOException,  
           GeneralSecurityException 
{
    
    String s = "1.2.840.113549.3.2";
    
    AlgorithmParameterGenerator algorithmparametergenerator = AlgorithmParameterGenerator.getInstance(s);
    AlgorithmParameters algorithmparameters = algorithmparametergenerator.generateParameters();
    ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(algorithmparameters.getEncoded("ASN.1"));
    ASN1InputStream asn1inputstream = new ASN1InputStream(bytearrayinputstream);
    ASN1Primitive derobject = asn1inputstream.readObject();
    KeyGenerator keygenerator = KeyGenerator.getInstance(s);
    keygenerator.init(128);
    SecretKey secretkey = keygenerator.generateKey();
    Cipher cipher = Cipher.getInstance(s);
    cipher.init(1, secretkey, algorithmparameters);
    byte[] abyte1 = cipher.doFinal(in);
    DEROctetString deroctetstring = new DEROctetString(abyte1);
    KeyTransRecipientInfo keytransrecipientinfo = computeRecipientInfo(cert, secretkey.getEncoded());
    DERSet derset = new DERSet(new RecipientInfo(keytransrecipientinfo));
    AlgorithmIdentifier algorithmidentifier = new AlgorithmIdentifier(new ASN1ObjectIdentifier(s), derobject);
    EncryptedContentInfo encryptedcontentinfo = 
        new EncryptedContentInfo(PKCSObjectIdentifiers.data, algorithmidentifier, deroctetstring);
    EnvelopedData env = new EnvelopedData(null, derset, encryptedcontentinfo, (org.bouncycastle.asn1.ASN1Set) null);
    ContentInfo contentinfo = 
        new ContentInfo(PKCSObjectIdentifiers.envelopedData, env);
    return contentinfo.toASN1Primitive();        
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:30,代码来源:PdfPublicKeySecurityHandler.java

示例13: initKey

import java.security.AlgorithmParameterGenerator; //导入方法依赖的package包/类
/**
 * 初始化密钥对
 * @return Map 甲方密钥的Map
 * */
public static Map<String,Object> initKey() throws Exception{
	//加入对BouncyCastle支持
	Security.addProvider(new BouncyCastleProvider());
	AlgorithmParameterGenerator apg=AlgorithmParameterGenerator.getInstance(KEY_ALGORITHM);
	//初始化参数生成器
	apg.init(KEY_SIZE);
	//生成算法参数
	AlgorithmParameters params=apg.generateParameters();
	//构建参数材料
	DHParameterSpec elParams=(DHParameterSpec)params.getParameterSpec(DHParameterSpec.class);
	
	//实例化密钥生成器
	KeyPairGenerator kpg=KeyPairGenerator.getInstance(KEY_ALGORITHM) ;
	
	//初始化密钥对生成器
	kpg.initialize(elParams,new SecureRandom());
	
	KeyPair keyPair=kpg.generateKeyPair();
	//甲方公钥
	PublicKey publicKey= keyPair.getPublic();
	//甲方私钥
	PrivateKey privateKey= keyPair.getPrivate();
	//将密钥存储在map中
	Map<String,Object> keyMap=new HashMap<String,Object>();
	keyMap.put(PUBLIC_KEY, publicKey);
	keyMap.put(PRIVATE_KEY, privateKey);
	return keyMap;
	
}
 
开发者ID:Tim9Liu9,项目名称:java_security,代码行数:34,代码来源:ElGamalTest2.java

示例14: testAlgorithmParameterGenerator

import java.security.AlgorithmParameterGenerator; //导入方法依赖的package包/类
@TestTargets({
    @TestTargetNew(
            level=TestLevel.ADDITIONAL,
            method="getInstance",
            args={String.class}
    ),
    @TestTargetNew(
            level=TestLevel.ADDITIONAL,
            method="init",
            args={int.class}
    ),
    @TestTargetNew(
            level=TestLevel.COMPLETE,
            method="method",
            args={}
    )
})
public void testAlgorithmParameterGenerator() {
    AlgorithmParameterGenerator generator = null;
    try {
        generator = AlgorithmParameterGenerator.getInstance(algorithmName);
    } catch (NoSuchAlgorithmException e) {
        fail(e.getMessage());
    }

    generator.init(1024);

    AlgorithmParameters parameters = generator.generateParameters();

    assertNotNull("generated parameters are null", parameters);

    helper.test(parameters);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:34,代码来源:AlgorithmParameterGeneratorTest.java

示例15: test_generateParameters

import java.security.AlgorithmParameterGenerator; //导入方法依赖的package包/类
/**
 * @tests java.security.AlgorithmParameterGenerator#generateParameters()
 */
public void test_generateParameters() throws Exception {

	//fail("Takes ages. Problem with SecureRandom and stub math ?");
	
	// Test for method java.security.AlgorithmParameters
	// java.security.AlgorithmParameterGenerator.generateParameters()
	AlgorithmParameterGenerator gen = AlgorithmParameterGenerator
			.getInstance("DSA");
	gen.init(1024);

	// WARNING - The next line can take MINUTES to run
	AlgorithmParameters params = gen.generateParameters();
	assertNotNull("params is null", params);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:18,代码来源:AlgorithmParameterGenerator3Test.java


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