Package org.signal.libsignal.protocol
Class SessionCipher
- java.lang.Object
-
- org.signal.libsignal.protocol.SessionCipher
-
public class SessionCipher extends java.lang.ObjectThe main entry point for Signal Protocol encrypt/decrypt operations. Once a session has been established withSessionBuilder, this class can be used for all encrypt/decrypt operations within that session. This class is not thread-safe.
-
-
Constructor Summary
Constructors Constructor Description SessionCipher(SessionStore sessionStore, PreKeyStore preKeyStore, SignedPreKeyStore signedPreKeyStore, IdentityKeyStore identityKeyStore, SignalProtocolAddress remoteAddress)Construct a SessionCipher for encrypt/decrypt operations on a session.SessionCipher(SignalProtocolStore store, SignalProtocolAddress remoteAddress)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]decrypt(PreKeySignalMessage ciphertext)Decrypt a message.byte[]decrypt(SignalMessage ciphertext)Decrypt a message.CiphertextMessageencrypt(byte[] paddedMessage)Encrypt a message.intgetRemoteRegistrationId()intgetSessionVersion()
-
-
-
Constructor Detail
-
SessionCipher
public SessionCipher(SessionStore sessionStore, PreKeyStore preKeyStore, SignedPreKeyStore signedPreKeyStore, IdentityKeyStore identityKeyStore, SignalProtocolAddress remoteAddress)
Construct a SessionCipher for encrypt/decrypt operations on a session. In order to use SessionCipher, a session must have already been created and stored usingSessionBuilder.- Parameters:
sessionStore- TheSessionStorethat contains a session for this recipient.remoteAddress- The remote address that messages will be encrypted to or decrypted from.
-
SessionCipher
public SessionCipher(SignalProtocolStore store, SignalProtocolAddress remoteAddress)
-
-
Method Detail
-
encrypt
public CiphertextMessage encrypt(byte[] paddedMessage) throws UntrustedIdentityException
Encrypt a message.- Parameters:
paddedMessage- The plaintext message bytes, optionally padded to a constant multiple.- Returns:
- A ciphertext message encrypted to the recipient+device tuple.
- Throws:
UntrustedIdentityException
-
decrypt
public byte[] decrypt(PreKeySignalMessage ciphertext) throws DuplicateMessageException, InvalidMessageException, InvalidKeyIdException, InvalidKeyException, UntrustedIdentityException
Decrypt a message.- Parameters:
ciphertext- ThePreKeySignalMessageto decrypt.- Returns:
- The plaintext.
- Throws:
InvalidMessageException- if the input is not valid ciphertext.DuplicateMessageException- if the input is a message that has already been received.InvalidKeyIdException- when there is no localPreKeyRecordthat corresponds to the PreKey ID in the message.InvalidKeyException- when the message is formatted incorrectly.UntrustedIdentityException- when theIdentityKeyof the sender is untrusted.
-
decrypt
public byte[] decrypt(SignalMessage ciphertext) throws InvalidMessageException, InvalidVersionException, DuplicateMessageException, NoSessionException, UntrustedIdentityException
Decrypt a message.- Parameters:
ciphertext- TheSignalMessageto decrypt.- Returns:
- The plaintext.
- Throws:
InvalidMessageException- if the input is not valid ciphertext.InvalidVersionException- if the message version does not match the session version.DuplicateMessageException- if the input is a message that has already been received.NoSessionException- if there is no established session for this contact.UntrustedIdentityException
-
getRemoteRegistrationId
public int getRemoteRegistrationId()
-
getSessionVersion
public int getSessionVersion()
-
-