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

Java RSAKeyPairGenerator类代码示例

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

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



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

示例1: generateKeyRingGenerator

import org.spongycastle.crypto.generators.RSAKeyPairGenerator; //导入依赖的package包/类
public final static PGPKeyRingGenerator generateKeyRingGenerator (String keyId, char[] pass) throws PGPException{
    RSAKeyPairGenerator kpg = new RSAKeyPairGenerator();
    kpg.init(new RSAKeyGenerationParameters(BigInteger.valueOf(0x10001), new SecureRandom(), 4096, 12));
    PGPKeyPair rsakp_sign = new BcPGPKeyPair(PGPPublicKey.RSA_SIGN, kpg.generateKeyPair(), new Date());
    PGPKeyPair rsakp_enc = new BcPGPKeyPair(PGPPublicKey.RSA_ENCRYPT, kpg.generateKeyPair(), new Date());
    PGPSignatureSubpacketGenerator signhashgen = new PGPSignatureSubpacketGenerator();
    signhashgen.setKeyFlags(false, KeyFlags.SIGN_DATA|KeyFlags.CERTIFY_OTHER|KeyFlags.SHARED);
    signhashgen.setPreferredSymmetricAlgorithms(false, new int[]{SymmetricKeyAlgorithmTags.AES_256, SymmetricKeyAlgorithmTags.AES_192, SymmetricKeyAlgorithmTags.AES_128});
    signhashgen.setPreferredHashAlgorithms(false, new int[]{HashAlgorithmTags.SHA256, HashAlgorithmTags.SHA1, HashAlgorithmTags.SHA384, HashAlgorithmTags.SHA512, HashAlgorithmTags.SHA224});
    signhashgen.setFeature(false, Features.FEATURE_MODIFICATION_DETECTION);
    PGPSignatureSubpacketGenerator enchashgen = new PGPSignatureSubpacketGenerator();
    enchashgen.setKeyFlags(false, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE);
    PGPDigestCalculator sha1Calc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA1);
    PGPDigestCalculator sha256Calc = new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA256);
    PBESecretKeyEncryptor pske = (new BcPBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_256, sha256Calc, 0xc0)).build(pass);
    PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator (PGPSignature.POSITIVE_CERTIFICATION, rsakp_sign,
            keyId, sha1Calc, signhashgen.generate(), null, new BcPGPContentSignerBuilder(rsakp_sign.getPublicKey().getAlgorithm(),
            HashAlgorithmTags.SHA1), pske);
    keyRingGen.addSubKey(rsakp_enc, enchashgen.generate(), null);
    return keyRingGen;
}
 
开发者ID:guardianproject,项目名称:proofmode,代码行数:22,代码来源:PgpUtils.java


示例2: createKeyRingGenerator

import org.spongycastle.crypto.generators.RSAKeyPairGenerator; //导入依赖的package包/类
/**
 * creates and initializes a PGP Key Ring Generator
 *
 * @param userId
 *    the user id to use
 * @param password
 *    the password used for the private key
 * @param keySize
 *    the key size used for the keys
 * @return the initialized key ring generator or null if something goes wrong
 */
private PGPKeyRingGenerator createKeyRingGenerator(String userId, String password, int keySize) {
  LOGGER.trace("createKeyRingGenerator(String, String, int)");
  LOGGER.trace("User ID: {}, Password: {}, Key Size: {}", userId, password == null ? "not set" : "********", keySize);
  PGPKeyRingGenerator generator = null;
  try {
    LOGGER.debug("Creating RSA key pair generator");
    RSAKeyPairGenerator generator1 = new RSAKeyPairGenerator();
    generator1.init(new RSAKeyGenerationParameters(BigInteger.valueOf(0x10001), getSecureRandom(), keySize, 12));
    LOGGER.debug("Generating Signing Key Pair");
    BcPGPKeyPair signingKeyPair = new BcPGPKeyPair(PGPPublicKey.RSA_SIGN, generator1.generateKeyPair(), new Date());
    LOGGER.debug("Generating Encyption Key Pair");
    BcPGPKeyPair encryptionKeyPair = new BcPGPKeyPair(PGPPublicKey.RSA_ENCRYPT, generator1.generateKeyPair(), new Date());
    LOGGER.debug("Generating Signature Key Properties");
    PGPSignatureSubpacketGenerator signatureSubpacketGenerator = new PGPSignatureSubpacketGenerator();
    signatureSubpacketGenerator.setKeyFlags(false, KeyFlags.SIGN_DATA | KeyFlags.CERTIFY_OTHER);
    signatureSubpacketGenerator.setPreferredSymmetricAlgorithms(false, getPreferredEncryptionAlgorithms());
    signatureSubpacketGenerator.setPreferredHashAlgorithms(false, getPreferredHashingAlgorithms());
    signatureSubpacketGenerator.setPreferredCompressionAlgorithms(false, getPreferredCompressionAlgorithms());

    LOGGER.debug("Generating Encyption Key Properties");
    PGPSignatureSubpacketGenerator encryptionSubpacketGenerator = new PGPSignatureSubpacketGenerator();
    encryptionSubpacketGenerator.setKeyFlags(false, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE);

    LOGGER.info("Creating PGP Key Ring Generator");
    generator = new PGPKeyRingGenerator(PGPPublicKey.RSA_SIGN, signingKeyPair, userId, new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA1), signatureSubpacketGenerator.generate(), null, new BcPGPContentSignerBuilder(PGPPublicKey.RSA_SIGN, HashAlgorithmTags.SHA256), new BcPBESecretKeyEncryptorBuilder(getEncryptionAlgorithm()).build(password.toCharArray()));
    generator.addSubKey(encryptionKeyPair, encryptionSubpacketGenerator.generate(), null);
  } catch (PGPException e) {
    LOGGER.error("{}", e.getMessage());
    generator = null;
  }
  return generator;
}
 
开发者ID:sniggle,项目名称:simple-pgp,代码行数:44,代码来源:PGPKeyPairGenerator.java


示例3: ProtocolServer

import org.spongycastle.crypto.generators.RSAKeyPairGenerator; //导入依赖的package包/类
public ProtocolServer(Class protocolInterfaceType, Object protocolImpl){
    RSAKeyPairGenerator rsaGen = new RSAKeyPairGenerator();
    rsaGen.init(new RSAKeyGenerationParameters(BigInteger.valueOf(0x1001), new SecureRandom(), 2048, 25));
    keyPair = rsaGen.generateKeyPair();

    ChannelFactory channelFactory = new NioServerSocketChannelFactory(
            Executors.newCachedThreadPool(),
            Executors.newCachedThreadPool()
    );
    nettyServer = new NettyServer(new ReflectResponder(
            protocolInterfaceType,
            protocolImpl), new InetSocketAddress(7001),
            channelFactory, new SSLChannelPipelineFactory(keyPair),
            null);
}
 
开发者ID:ChristopherMann,项目名称:2FactorWallet,代码行数:16,代码来源:ProtocolServer.java


示例4: generateKeyPair

import org.spongycastle.crypto.generators.RSAKeyPairGenerator; //导入依赖的package包/类
@Override
public AsymmetricCipherKeyPair generateKeyPair() {
    // Can't return null as public key is extracted from it
    RSAKeyPairGenerator gen = new RSAKeyPairGenerator();
    RSAKeyGenerationParameters params = new RSAKeyGenerationParameters(
            BigInteger.valueOf(0x10001), getSecureRandom(), 32, 1);
    gen.init(params);
    return gen.generateKeyPair();
}
 
开发者ID:dustyneuron,项目名称:bitprivacy,代码行数:10,代码来源:MockBlinding.java


示例5: generateKey

import org.spongycastle.crypto.generators.RSAKeyPairGenerator; //导入依赖的package包/类
@Override
public PGPKeyRingGenerator generateKey(String email, char[] password) throws Exception {
    RSAKeyPairGenerator rsaKeyPairGenerator=new RSAKeyPairGenerator();
    rsaKeyPairGenerator.init(new RSAKeyGenerationParameters(BigInteger.valueOf(0x10001),new SecureRandom(),2048,12));
    PGPKeyPair keyPair=new BcPGPKeyPair(PGPPublicKey.RSA_SIGN,rsaKeyPairGenerator.generateKeyPair(),new Date());
    PGPKeyPair enKeyPair=new BcPGPKeyPair(PGPPublicKey.RSA_ENCRYPT,rsaKeyPairGenerator.generateKeyPair(),new Date());

    // Add a self-signature on the id
    PGPSignatureSubpacketGenerator signhashgen =
            new PGPSignatureSubpacketGenerator();

    // Add signed metadata on the signature.
    // 1) Declare its purpose
    signhashgen.setKeyFlags
            (false, KeyFlags.SIGN_DATA|KeyFlags.CERTIFY_OTHER);
    // 2) Set preferences for secondary crypto algorithms to use
    //    when sending messages to this key.
    signhashgen.setPreferredSymmetricAlgorithms
            (false, new int[] {
                    SymmetricKeyAlgorithmTags.AES_256,
                    SymmetricKeyAlgorithmTags.AES_192,
                    SymmetricKeyAlgorithmTags.AES_128
            });
    signhashgen.setPreferredHashAlgorithms
            (false, new int[] {
                    HashAlgorithmTags.SHA256,
                    HashAlgorithmTags.SHA1,
                    HashAlgorithmTags.SHA384,
                    HashAlgorithmTags.SHA512,
                    HashAlgorithmTags.SHA224,
            });
    // 3) Request senders add additional checksums to the
    //    message (useful when verifying unsigned messages.)
    signhashgen.setFeature
            (false, Features.FEATURE_MODIFICATION_DETECTION);

    // Create a signature on the encryption subkey.
    PGPSignatureSubpacketGenerator enchashgen =
            new PGPSignatureSubpacketGenerator();
    // Add metadata to declare its purpose
    enchashgen.setKeyFlags
            (false, KeyFlags.ENCRYPT_COMMS|KeyFlags.ENCRYPT_STORAGE);

    // Objects used to encrypt the secret key.
    PGPDigestCalculator sha1Calc =
            new BcPGPDigestCalculatorProvider()
                    .get(HashAlgorithmTags.SHA1);
    PGPDigestCalculator sha256Calc =
            new BcPGPDigestCalculatorProvider()
                    .get(HashAlgorithmTags.SHA256);


    PBESecretKeyEncryptor pske =
            (new BcPBESecretKeyEncryptorBuilder
                    (PGPEncryptedData.AES_256, sha256Calc, 0xc0))
                    .build(password);

    // Finally, create the keyring itself. The constructor
    // takes parameters that allow it to generate the self
    // signature.
    PGPKeyRingGenerator keyRingGen =
            new PGPKeyRingGenerator
                    (PGPSignature.POSITIVE_CERTIFICATION, keyPair,
                            email, sha1Calc, signhashgen.generate(), null,
                            new BcPGPContentSignerBuilder
                                    (keyPair.getPublicKey().getAlgorithm(),
                                            HashAlgorithmTags.SHA1),
                            pske);

    // Add our encryption subkey, together with its signature.
    keyRingGen.addSubKey
            (enKeyPair, enchashgen.generate(), null);
    return keyRingGen;
}
 
开发者ID:mosamabinomar,项目名称:RootPGPExplorer,代码行数:75,代码来源:KeyManagement.java


示例6: generateCertificate

import org.spongycastle.crypto.generators.RSAKeyPairGenerator; //导入依赖的package包/类
/**
 * Create a self-signed X.509 Certificate
 *
 * @param dn the X.509 Distinguished Name, eg "CN=Test, L=London, C=GB"
 */
private X509Certificate generateCertificate(String dn) throws Exception {

    X500Name x500nameIssuer = new X500Name("CN=TestCA,L=Den Haag, C=NL");
    X500Name x500nameSubject = new X500Name(dn);
    BigInteger serial = new BigInteger(64, new Random());
    Date notBefore = new Date();

    // Set Expiration Date
    Calendar tempCal = Calendar.getInstance();
    tempCal.setTime(notBefore);
    tempCal.add(Calendar.DATE, 365);
    Date notAfter = tempCal.getTime();

    // Create Pubkey
    RSAKeyPairGenerator keyGen = new RSAKeyPairGenerator();
    keyGen.init(new RSAKeyGenerationParameters(new BigInteger("10001", 16), SecureRandom.getInstance("SHA1PRNG"), 1024, 80));
    AsymmetricCipherKeyPair keys = keyGen.generateKeyPair();
    SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(keys.getPublic());

    X509v3CertificateBuilder builder = new X509v3CertificateBuilder(
            x500nameIssuer,
            serial,
            notBefore,
            notAfter,
            Locale.US,
            x500nameSubject,
            subPubKeyInfo
    );

    try {
        // Export Private Key Info into Java PrivateKey
        BigInteger modulus = ((RSAKeyParameters) keys.getPrivate()).getModulus();
        BigInteger exponent = ((RSAKeyParameters) keys.getPrivate()).getExponent();
        RSAPrivateKeySpec privateSpec = new RSAPrivateKeySpec(modulus, exponent);
        KeyFactory factory = KeyFactory.getInstance("RSA");

        ContentSigner sigGen = new JcaContentSignerBuilder("SHA1withRSA").build(factory.generatePrivate(privateSpec));

        X509CertificateHolder holder = builder.build(sigGen);
        InputStream is = new ByteArrayInputStream(holder.toASN1Structure().getEncoded());
        return (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(is);

    } catch (OperatorCreationException e) {
        e.printStackTrace();
    }

    throw new Exception("Unable to Create Test X509 Cert");
}
 
开发者ID:netkicorp,项目名称:java-wns-resolver,代码行数:54,代码来源:TLSAValidatorTest.java


示例7: testOpenPgp

import org.spongycastle.crypto.generators.RSAKeyPairGenerator; //导入依赖的package包/类
/**
 * https://github.com/wesabe/grendel/blob/master/src/test/java/com/wesabe/
 * grendel/openpgp/tests/KeySetGeneratorTest.java
 * 
 * @throws PGPException
 */
@Test
public void testOpenPgp() throws PGPException {
	String id = "[email protected]";
	String pass = "hello";
	int s2kcount = 0xc1;
	// http://bouncycastle-pgp-cookbook.blogspot.tw/2013/01/generating-rsa-keys.html

	RSAKeyPairGenerator kpg = new RSAKeyPairGenerator();
	kpg.init(new RSAKeyGenerationParameters(BigInteger.valueOf(0x10001),
			new SecureRandom(), 2048, 12));

	BcPGPKeyPair bkpSign = new BcPGPKeyPair(PGPPublicKey.RSA_SIGN,
			kpg.generateKeyPair(), new Date());

	assertNotNull(bkpSign);
	BcPGPKeyPair bkpEncrypt = new BcPGPKeyPair(PGPPublicKey.RSA_ENCRYPT,
			kpg.generateKeyPair(), new Date());

	assertNotNull(bkpEncrypt);

	PGPSignatureSubpacketGenerator signhashgen = new PGPSignatureSubpacketGenerator();

	signhashgen.setKeyFlags(false, KeyFlags.SIGN_DATA
			| KeyFlags.CERTIFY_OTHER);
	signhashgen.setPreferredSymmetricAlgorithms(false, new int[] {
			SymmetricKeyAlgorithmTags.AES_256,
			SymmetricKeyAlgorithmTags.AES_192,
			SymmetricKeyAlgorithmTags.AES_128 });
	signhashgen.setPreferredHashAlgorithms(false, new int[] {
			HashAlgorithmTags.SHA256, HashAlgorithmTags.SHA1,
			HashAlgorithmTags.SHA384, HashAlgorithmTags.SHA512,
			HashAlgorithmTags.SHA224, });

	signhashgen.setFeature(false, Features.FEATURE_MODIFICATION_DETECTION);

	PGPSignatureSubpacketGenerator enchashgen = new PGPSignatureSubpacketGenerator();
	enchashgen.setKeyFlags(false, KeyFlags.ENCRYPT_COMMS
			| KeyFlags.ENCRYPT_STORAGE);

	PGPDigestCalculator sha1Calc = new BcPGPDigestCalculatorProvider()
			.get(HashAlgorithmTags.SHA1);
	PGPDigestCalculator sha256Calc = new BcPGPDigestCalculatorProvider()
			.get(HashAlgorithmTags.SHA256);

	// bcpg 1.48 exposes this API that includes s2kcount. Earlier
	// versions use a default of 0x60.
	PBESecretKeyEncryptor pske = (new BcPBESecretKeyEncryptorBuilder(
			PGPEncryptedData.AES_256, sha256Calc))
			.build(pass.toCharArray());

	// Finally, create the keyring itself. The constructor
	// takes parameters that allow it to generate the self
	// signature.
	PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(
			PGPSignature.POSITIVE_CERTIFICATION, bkpSign, id, sha1Calc,
			signhashgen.generate(), null, new BcPGPContentSignerBuilder(
					bkpSign.getPublicKey().getAlgorithm(),
					HashAlgorithmTags.SHA1), pske);

	// Add our encryption subkey, together with its signature.
	keyRingGen.addSubKey(bkpEncrypt, enchashgen.generate(), null);
	assertNotNull(keyRingGen);
}
 
开发者ID:y12studio,项目名称:bkbc-tools,代码行数:70,代码来源:MainPrivKeyShareTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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