Search in sources :

Example 1 with JcaPGPKeyPair

use of org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair in project definitive-guide-jakarta-ee-security by Apress.

the class PGPKeyPairGeneratorWithRSA method main.

public static void main(String[] args) throws PGPException, NoSuchAlgorithmException, IOException {
    char[] passphrase = "testpass".toCharArray();
    String identity = "testidentity";
    KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");
    keygen.initialize(2048);
    KeyPair keyPair = keygen.generateKeyPair();
    PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
    PGPKeyPair pgpKeyPair = new JcaPGPKeyPair(PGPPublicKey.RSA_GENERAL, keyPair, new Date());
    PGPSecretKey secretKey = new PGPSecretKey(PGPSignature.DEFAULT_CERTIFICATION, pgpKeyPair, identity, sha1Calc, null, null, new JcaPGPContentSignerBuilder(pgpKeyPair.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.CAST5, sha1Calc).setProvider(new BouncyCastleProvider()).build(passphrase));
    System.out.println("Public key: " + Base64.getEncoder().encodeToString(secretKey.getPublicKey().getEncoded()));
    System.out.println("Private key: " + Base64.getEncoder().encodeToString(secretKey.getEncoded()));
}
Also used : KeyPair(java.security.KeyPair) JcaPGPKeyPair(org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair) PGPDigestCalculator(org.bouncycastle.openpgp.operator.PGPDigestCalculator) JcaPGPKeyPair(org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair) JcaPGPKeyPair(org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair) KeyPairGenerator(java.security.KeyPairGenerator) Date(java.util.Date) JcaPGPContentSignerBuilder(org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder) JcaPGPDigestCalculatorProviderBuilder(org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder) JcePBESecretKeyEncryptorBuilder(org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 2 with JcaPGPKeyPair

use of org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair in project codebunker by gazampa.

the class PGPExporter method convertToPGPKeyPair.

private PGPKeyPair convertToPGPKeyPair(KeyPair pair) {
    PGPKeyPair keyPair = null;
    try {
        keyPair = new JcaPGPKeyPair(PGPPublicKey.RSA_GENERAL, pair, new Date());
    } catch (PGPException pgpe) {
        System.out.println("problem converting jca key pair");
    }
    setPGPKeyPair(keyPair);
    return keyPair;
}
Also used : PGPException(org.bouncycastle.openpgp.PGPException) JcaPGPKeyPair(org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair) PGPKeyPair(org.bouncycastle.openpgp.PGPKeyPair) JcaPGPKeyPair(org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair) Date(java.util.Date)

Example 3 with JcaPGPKeyPair

use of org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method newSecretKey.

public PGPSecretKey newSecretKey() throws NoSuchAlgorithmException, NoSuchProviderException, PGPException {
    final KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    kpg.initialize(2048);
    final KeyPair pair = kpg.generateKeyPair();
    final PGPDigestCalculator sha1Calc = new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1);
    final PGPKeyPair pkp = new JcaPGPKeyPair(PGPPublicKey.RSA_GENERAL, pair, new Date());
    return new PGPSecretKey(PGPSignature.DEFAULT_CERTIFICATION, pkp, "example@example.com", sha1Calc, null, null, new JcaPGPContentSignerBuilder(pkp.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA256), new JcePBESecretKeyEncryptorBuilder(PGPEncryptedData.AES_192, sha1Calc).setProvider(new BouncyCastleFipsProvider()).build("passphrase".toCharArray()));
}
Also used : KeyPair(java.security.KeyPair) PGPKeyPair(org.bouncycastle.openpgp.PGPKeyPair) JcaPGPKeyPair(org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair) JcaPGPContentSignerBuilder(org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder) BouncyCastleFipsProvider(org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider) PGPDigestCalculator(org.bouncycastle.openpgp.operator.PGPDigestCalculator) PGPKeyPair(org.bouncycastle.openpgp.PGPKeyPair) JcaPGPKeyPair(org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair) PGPSecretKey(org.bouncycastle.openpgp.PGPSecretKey) JcaPGPKeyPair(org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair) KeyPairGenerator(java.security.KeyPairGenerator) JcaPGPDigestCalculatorProviderBuilder(org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder) Date(java.util.Date) JcePBESecretKeyEncryptorBuilder(org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder)

Example 4 with JcaPGPKeyPair

use of org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair in project scm-manager by scm-manager.

the class GPGKeyPairGenerator method generateKeyPair.

static PGPKeyRingGenerator generateKeyPair() throws PGPException, NoSuchProviderException, NoSuchAlgorithmException {
    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", "BC");
    keyPairGenerator.initialize(2048);
    KeyPair pair = keyPairGenerator.generateKeyPair();
    PGPKeyPair keyPair = new JcaPGPKeyPair(PublicKeyAlgorithmTags.RSA_GENERAL, pair, new Date());
    final User user = SecurityUtils.getSubject().getPrincipals().oneByType(User.class);
    final Person person = new Person(user.getDisplayName(), user.getMail());
    return new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, keyPair, person.toString(), new JcaPGPDigestCalculatorProviderBuilder().build().get(HashAlgorithmTags.SHA1), null, null, new JcaPGPContentSignerBuilder(PublicKeyAlgorithmTags.RSA_GENERAL, HashAlgorithmTags.SHA1), new JcePBESecretKeyEncryptorBuilder(SymmetricKeyAlgorithmTags.AES_256).build(new char[] {}));
}
Also used : PGPKeyRingGenerator(org.bouncycastle.openpgp.PGPKeyRingGenerator) KeyPair(java.security.KeyPair) JcaPGPKeyPair(org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair) PGPKeyPair(org.bouncycastle.openpgp.PGPKeyPair) User(sonia.scm.user.User) JcaPGPContentSignerBuilder(org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder) JcaPGPKeyPair(org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair) PGPKeyPair(org.bouncycastle.openpgp.PGPKeyPair) JcaPGPKeyPair(org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair) KeyPairGenerator(java.security.KeyPairGenerator) JcaPGPDigestCalculatorProviderBuilder(org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder) Person(sonia.scm.repository.Person) Date(java.util.Date) JcePBESecretKeyEncryptorBuilder(org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder)

Example 5 with JcaPGPKeyPair

use of org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair in project scm-manager by scm-manager.

the class GitChangesetConverterTest method createKeyPair.

private PGPKeyPair createKeyPair() throws PGPException, NoSuchProviderException, NoSuchAlgorithmException {
    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", "BC");
    // we use a small key size to speedup test, a much larger size should be used for production
    keyPairGenerator.initialize(512);
    KeyPair pair = keyPairGenerator.generateKeyPair();
    return new JcaPGPKeyPair(PGPPublicKey.RSA_GENERAL, pair, new Date());
}
Also used : KeyPair(java.security.KeyPair) PGPKeyPair(org.bouncycastle.openpgp.PGPKeyPair) JcaPGPKeyPair(org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair) JcaPGPKeyPair(org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair) KeyPairGenerator(java.security.KeyPairGenerator) Date(java.util.Date)

Aggregations

JcaPGPKeyPair (org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyPair)7 Date (java.util.Date)6 PGPKeyPair (org.bouncycastle.openpgp.PGPKeyPair)6 KeyPair (java.security.KeyPair)5 KeyPairGenerator (java.security.KeyPairGenerator)5 JcaPGPContentSignerBuilder (org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder)4 JcaPGPDigestCalculatorProviderBuilder (org.bouncycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder)4 PGPDigestCalculator (org.bouncycastle.openpgp.operator.PGPDigestCalculator)3 JcePBESecretKeyEncryptorBuilder (org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder)3 PGPKeyRingGenerator (org.bouncycastle.openpgp.PGPKeyRingGenerator)2 AsymmetricCipherKeyPair (org.bouncycastle.crypto.AsymmetricCipherKeyPair)1 AsymmetricKeyParameter (org.bouncycastle.crypto.params.AsymmetricKeyParameter)1 BouncyCastleFipsProvider (org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider)1 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)1 ECNamedCurveGenParameterSpec (org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec)1 PGPException (org.bouncycastle.openpgp.PGPException)1 PGPPublicKeyRing (org.bouncycastle.openpgp.PGPPublicKeyRing)1 PGPSecretKey (org.bouncycastle.openpgp.PGPSecretKey)1 PGPSecretKeyRing (org.bouncycastle.openpgp.PGPSecretKeyRing)1 PGPSignatureSubpacketGenerator (org.bouncycastle.openpgp.PGPSignatureSubpacketGenerator)1