Search in sources :

Example 6 with OpenPgpContact

use of org.jivesoftware.smackx.ox.OpenPgpContact in project Smack by igniterealtime.

the class OXInstantMessagingManager method signAndEncrypt.

/**
 * Wrap some {@code payload} into a {@link SigncryptElement}, sign and encrypt it for {@code contacts} and ourselves.
 *
 * @param contacts recipients of the message
 * @param payload payload which will be encrypted and signed
 *
 * @return encrypted and signed {@link OpenPgpElement}, along with {@link OpenPgpMetadata} about the
 * encryption + signatures.
 *
 * @throws SmackException.NotLoggedInException in case we are not logged in
 * @throws IOException IO is dangerous (we need to read keys)
 * @throws PGPException in case encryption goes wrong
 */
public OpenPgpElementAndMetadata signAndEncrypt(Set<OpenPgpContact> contacts, List<ExtensionElement> payload) throws SmackException.NotLoggedInException, IOException, PGPException {
    Set<Jid> jids = new HashSet<>();
    for (OpenPgpContact contact : contacts) {
        jids.add(contact.getJid());
    }
    jids.add(openPgpManager.getOpenPgpSelf().getJid());
    SigncryptElement signcryptElement = new SigncryptElement(jids, payload);
    OpenPgpElementAndMetadata encrypted = openPgpManager.getOpenPgpProvider().signAndEncrypt(signcryptElement, openPgpManager.getOpenPgpSelf(), contacts);
    return encrypted;
}
Also used : SigncryptElement(org.jivesoftware.smackx.ox.element.SigncryptElement) Jid(org.jxmpp.jid.Jid) BareJid(org.jxmpp.jid.BareJid) HashSet(java.util.HashSet) OpenPgpContact(org.jivesoftware.smackx.ox.OpenPgpContact) OpenPgpElementAndMetadata(org.jivesoftware.smackx.ox.crypto.OpenPgpElementAndMetadata)

Aggregations

OpenPgpContact (org.jivesoftware.smackx.ox.OpenPgpContact)6 PGPPublicKeyRingCollection (org.bouncycastle.openpgp.PGPPublicKeyRingCollection)3 SigncryptElement (org.jivesoftware.smackx.ox.element.SigncryptElement)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 Message (org.jivesoftware.smack.packet.Message)2 PainlessOpenPgpProvider (org.jivesoftware.smackx.ox.crypto.PainlessOpenPgpProvider)2 OpenPgpElement (org.jivesoftware.smackx.ox.element.OpenPgpElement)2 FileBasedOpenPgpStore (org.jivesoftware.smackx.ox.store.filebased.FileBasedOpenPgpStore)2 OpenPgpMetadata (org.pgpainless.decryption_verification.OpenPgpMetadata)2 EncryptionOptions (org.pgpainless.encryption_signing.EncryptionOptions)2 EncryptionStream (org.pgpainless.encryption_signing.EncryptionStream)2 File (java.io.File)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)1 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)1 DummyConnection (org.jivesoftware.smack.DummyConnection)1 MessageBuilder (org.jivesoftware.smack.packet.MessageBuilder)1 OpenPgpManager (org.jivesoftware.smackx.ox.OpenPgpManager)1