List of usage examples for org.bouncycastle.openpgp PGPSignatureSubpacketGenerator PGPSignatureSubpacketGenerator
public PGPSignatureSubpacketGenerator()
From source file:ubicrypt.core.crypto.PGPEC.java
License:Open Source License
private static PGPKeyRingGenerator keyRingGenerator(final PGPKeyPair masterKey, final PBESecretKeyEncryptor encryptor) { // Add a self-signature on the id final 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); try {//from w ww . j a v a 2 s . c om return new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, masterKey, Utils.machineName(), new BcPGPDigestCalculatorProvider().get(HashAlgorithmTags.SHA1), signhashgen.generate(), null, new BcPGPContentSignerBuilder(PGPPublicKey.ECDSA, HashAlgorithmTags.SHA256), encryptor); } catch (final PGPException e) { Throwables.propagate(e); } return null; }
From source file:ubicrypt.core.crypto.PGPEC.java
License:Open Source License
public static PGPPublicKey signPK(final PGPPublicKey pk, final PGPPrivateKey priv) { final PGPSignatureGenerator sGen = new PGPSignatureGenerator( new JcaPGPContentSignerBuilder(PGPPublicKey.ECDSA, PGPUtil.SHA256).setProvider("BC")); try {// w ww . ja v a 2 s .c om sGen.init(PGPSignature.DIRECT_KEY, priv); } catch (final PGPException e) { Throwables.propagate(e); } final PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator(); final PGPSignatureSubpacketVector packetVector = spGen.generate(); sGen.setHashedSubpackets(packetVector); try { return PGPPublicKey.addCertification(pk, sGen.generateCertification("id", pk)); } catch (final PGPException e) { Throwables.propagate(e); } return null; }