Example usage for org.bouncycastle.openpgp PGPSecretKeyRingCollection addSecretKeyRing

List of usage examples for org.bouncycastle.openpgp PGPSecretKeyRingCollection addSecretKeyRing

Introduction

In this page you can find the example usage for org.bouncycastle.openpgp PGPSecretKeyRingCollection addSecretKeyRing.

Prototype

public static PGPSecretKeyRingCollection addSecretKeyRing(PGPSecretKeyRingCollection ringCollection,
        PGPSecretKeyRing secretKeyRing) 

Source Link

Document

Return a new collection object containing the contents of the passed in collection and the passed in secret key ring.

Usage

From source file:org.jivesoftware.smackx.ox.store.abstr.AbstractOpenPgpKeyStore.java

License:Apache License

@Override
public void importSecretKey(BareJid owner, PGPSecretKeyRing secretKeys)
        throws IOException, PGPException, MissingUserIdOnKeyException {

    // TODO: Avoid 'new' use instance method.
    if (!new BareJidUserId.SecRingSelectionStrategy().accept(owner, secretKeys)) {
        throw new MissingUserIdOnKeyException(owner, new OpenPgpV4Fingerprint(secretKeys));
    }// w  ww . ja  v a 2 s.co m

    PGPSecretKeyRing importKeys = BCUtil.removeUnassociatedKeysFromKeyRing(secretKeys,
            secretKeys.getPublicKey());

    PGPSecretKeyRingCollection secretKeyRings = getSecretKeysOf(owner);
    try {
        if (secretKeyRings != null) {
            secretKeyRings = PGPSecretKeyRingCollection.addSecretKeyRing(secretKeyRings, importKeys);
        } else {
            secretKeyRings = BCUtil.keyRingsToKeyRingCollection(importKeys);
        }
    } catch (IllegalArgumentException e) {
        LOGGER.log(Level.INFO,
                "Skipping secret key ring " + Long.toHexString(importKeys.getPublicKey().getKeyID())
                        + " as it is already in the key ring of " + owner.toString());
    }
    this.secretKeyRingCollections.put(owner, secretKeyRings);
    writeSecretKeysOf(owner, secretKeyRings);
}