The Java KeyPairGenerator class (java.security.KeyPairGenerator) is used to generate asymmetric encryption / decryption key pairs. An asymmetric key pair consists of two keys. An asymmetric key pair consists of two keys. Feb 02, 2013 Java Code for RSA Key Generation. The following are top voted examples for showing how to use java.security.KeyPairGenerator.These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
The following are Jave code examples for showing how to use getInstance of the java.security.KeyPairGenerator class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Options are displayed, and you can transfer data by selecting the content. Is mobiletrans safe to use. MobileTrans provides many features as it supports different networks and also different mobiles.
PermalinkDownload windows 8 oem. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign uppackageorg.jdamico.bc.openpgp.utils; |
importjava.io.IOException; |
importjava.io.OutputStream; |
importjava.security.InvalidKeyException; |
importjava.security.NoSuchProviderException; |
importjava.security.PrivateKey; |
importjava.security.PublicKey; |
importjava.security.SignatureException; |
importjava.security.interfaces.RSAPrivateCrtKey; |
importjava.util.Date; |
importorg.bouncycastle.bcpg.ArmoredOutputStream; |
importorg.bouncycastle.bcpg.HashAlgorithmTags; |
importorg.bouncycastle.bcpg.RSASecretBCPGKey; |
importorg.bouncycastle.openpgp.PGPEncryptedData; |
importorg.bouncycastle.openpgp.PGPException; |
importorg.bouncycastle.openpgp.PGPKeyPair; |
importorg.bouncycastle.openpgp.PGPPrivateKey; |
importorg.bouncycastle.openpgp.PGPPublicKey; |
importorg.bouncycastle.openpgp.PGPSecretKey; |
importorg.bouncycastle.openpgp.PGPSignature; |
importorg.bouncycastle.openpgp.operator.PGPDigestCalculator; |
importorg.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; |
importorg.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder; |
importorg.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter; |
importorg.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; |
/** |
* A simple utility class that generates a RSA PGPPublicKey/PGPSecretKey pair. |
* <p> |
* usage: RSAKeyPairGenerator [-a] identity passPhrase |
* <p> |
* Where identity is the name to be associated with the public key. The keys are placed |
* in the files pub.[asc bpg] and secret.[asc bpg]. |
*/ |
publicclassRSAKeyPairGenerator |
{ |
publicvoidexportKeyPair( |
OutputStreamsecretOut, |
OutputStreampublicOut, |
PublicKeypublicKey, |
PrivateKeyprivateKey, |
Stringidentity, |
char[] passPhrase, |
booleanarmor) |
throwsIOException, InvalidKeyException, NoSuchProviderException, SignatureException, PGPException |
{ |
if (armor) |
{ |
secretOut =newArmoredOutputStream(secretOut); |
} |
PGPPublicKey a = (newJcaPGPKeyConverter().getPGPPublicKey(PGPPublicKey.RSA_GENERAL, publicKey, newDate())); |
RSAPrivateCrtKey rsK = (RSAPrivateCrtKey)privateKey; |
RSASecretBCPGKey privPk =newRSASecretBCPGKey(rsK.getPrivateExponent(), rsK.getPrimeP(), rsK.getPrimeQ()); |
PGPPrivateKey b =newPGPPrivateKey(a.getKeyID(), a.getPublicKeyPacket(), privPk); |
PGPDigestCalculator sha1Calc =newJcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1); |
PGPKeyPair keyPair =newPGPKeyPair(a,b); |
PGPSecretKey secretKey =newPGPSecretKey(PGPSignature.DEFAULT_CERTIFICATION, keyPair, identity, sha1Calc, null, null, newJcaPGPContentSignerBuilder(keyPair.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1), newJcePBESecretKeyEncryptorBuilder(PGPEncryptedData.CAST5, sha1Calc).setProvider('BC').build(passPhrase)); |
secretKey.encode(secretOut); |
secretOut.close(); |
if (armor) |
{ |
publicOut =newArmoredOutputStream(publicOut); |
} |
PGPPublicKey key = secretKey.getPublicKey(); |
key.encode(publicOut); |
publicOut.close(); |
} |
} |