static String decryptMessageElement ( OmemoElement element , CipherAndAuthTag cipherAndAuthTag ) throws CryptoFailedException { if ( ! element . isMessageElement ( ) ) { throw new IllegalArgumentException ( "decryptMessageElement cannot decrypt OmemoElement which is no MessageElement!" ) ; } if ( cipherAndAuthTag . getAuthTag ( ) == null || cipherAndAuthTag . getAuthTag ( ) . length != 16 ) { throw new CryptoFailedException ( "AuthenticationTag is null or has wrong length: " + ( cipherAndAuthTag . getAuthTag ( ) == null ? "null" : cipherAndAuthTag . getAuthTag ( ) . length ) ) ; } byte [ ] encryptedBody = payloadAndAuthTag ( element , cipherAndAuthTag . getAuthTag ( ) ) ; try { String plaintext = new String ( cipherAndAuthTag . getCipher ( ) . doFinal ( encryptedBody ) , StringUtils . UTF8 ) ; return plaintext ; } catch ( UnsupportedEncodingException | IllegalBlockSizeException | BadPaddingException e ) { throw new CryptoFailedException ( "decryptMessageElement could not decipher message body: " + e . getMessage ( ) ) ; } }
Use the symmetric key in cipherAndAuthTag to decrypt the payload of the omemoMessage . The decrypted payload will be the body of the returned Message .