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()));
}
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;
}
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()));
}
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[] {}));
}
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());
}
Aggregations