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 ; }
creates and initializes a PGP Key Ring Generator