public OpenPgpV4Fingerprint generateAndImportKeyPair ( BareJid ourJid ) throws NoSuchAlgorithmException , InvalidAlgorithmParameterException , NoSuchProviderException , PGPException , IOException { throwIfNoProviderSet ( ) ; OpenPgpStore store = provider . getStore ( ) ; PGPKeyRing keys = store . generateKeyRing ( ourJid ) ; try { store . importSecretKey ( ourJid , keys . getSecretKeys ( ) ) ; store . importPublicKey ( ourJid , keys . getPublicKeys ( ) ) ; } catch ( MissingUserIdOnKeyException e ) { // This should never throw, since we set our jid literally one line above this comment. throw new AssertionError ( e ) ; } OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint ( keys . getSecretKeys ( ) ) ; store . setTrust ( ourJid , fingerprint , OpenPgpTrustStore . Trust . trusted ) ; return fingerprint ; }
Generate a fresh OpenPGP key pair and import it .