Class OmemoMessageBuilder<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_Addr,T_ECPub,T_Bundle,T_Ciph>
- java.lang.Object
-
- org.jivesoftware.smackx.omemo.util.OmemoMessageBuilder<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_Addr,T_ECPub,T_Bundle,T_Ciph>
-
- Type Parameters:
T_IdKeyPair- IdentityKeyPair classT_IdKey- IdentityKey classT_PreKey- PreKey classT_SigPreKey- SignedPreKey classT_Sess- Session classT_Addr- Address classT_ECPub- Elliptic Curve PublicKey classT_Bundle- Bundle classT_Ciph- Cipher class
public class OmemoMessageBuilder<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_Addr,T_ECPub,T_Bundle,T_Ciph> extends java.lang.Object
Class used to build OMEMO messages.
-
-
Constructor Summary
Constructors Constructor Description OmemoMessageBuilder(OmemoDevice userDevice, OmemoTrustCallback callback, OmemoRatchet<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_Addr,T_ECPub,T_Bundle,T_Ciph> ratchet, byte[] aesKey, byte[] iv, java.lang.String message)Create an OmemoMessageBuilder.OmemoMessageBuilder(OmemoDevice userDevice, OmemoTrustCallback callback, OmemoRatchet<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_Addr,T_ECPub,T_Bundle,T_Ciph> ratchet, java.lang.String message)Create an OmemoMessageBuilder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRecipient(OmemoDevice contactsDevice)Add a new recipient device to the message.OmemoElementfinish()Assemble an OmemoMessageElement from the current state of the builder.static byte[]generateIv()Generate a 12 byte initialization vector for AES encryption.static byte[]generateKey(java.lang.String keyType, int keyLength)Generate a new AES key used to encrypt the message.
-
-
-
Constructor Detail
-
OmemoMessageBuilder
public OmemoMessageBuilder(OmemoDevice userDevice, OmemoTrustCallback callback, OmemoRatchet<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_Addr,T_ECPub,T_Bundle,T_Ciph> ratchet, byte[] aesKey, byte[] iv, java.lang.String message) throws javax.crypto.NoSuchPaddingException, javax.crypto.BadPaddingException, java.security.InvalidKeyException, java.security.NoSuchAlgorithmException, javax.crypto.IllegalBlockSizeException, java.security.InvalidAlgorithmParameterException
Create an OmemoMessageBuilder.- Parameters:
userDevice- our OmemoDevicecallback- trustCallback for querying trust decisionsratchet- our OmemoRatchetaesKey- aes message key used for message encryptioniv- initialization vector used for message encryptionmessage- message we want to send- Throws:
javax.crypto.NoSuchPaddingException- if the requested padding mechanism is not availble.javax.crypto.BadPaddingException- if the input data is not padded properly.java.security.InvalidKeyException- if the key is invalid.java.security.NoSuchAlgorithmException- if no such algorithm is available.javax.crypto.IllegalBlockSizeException- if the input data length is incorrect.java.security.InvalidAlgorithmParameterException- if the provided arguments are invalid.
-
OmemoMessageBuilder
public OmemoMessageBuilder(OmemoDevice userDevice, OmemoTrustCallback callback, OmemoRatchet<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_Addr,T_ECPub,T_Bundle,T_Ciph> ratchet, java.lang.String message) throws javax.crypto.NoSuchPaddingException, javax.crypto.BadPaddingException, java.security.InvalidKeyException, java.security.NoSuchAlgorithmException, javax.crypto.IllegalBlockSizeException, java.security.InvalidAlgorithmParameterException
Create an OmemoMessageBuilder.- Parameters:
userDevice- our OmemoDevicecallback- trustCallback for querying trust decisionsratchet- our OmemoRatchetmessage- message we want to send- Throws:
javax.crypto.NoSuchPaddingException- if the requested padding mechanism is not availble.javax.crypto.BadPaddingException- if the input data is not padded properly.java.security.InvalidKeyException- if the key is invalid.java.security.NoSuchAlgorithmException- if no such algorithm is available.javax.crypto.IllegalBlockSizeException- if the input data length is incorrect.java.security.InvalidAlgorithmParameterException- if the provided arguments are invalid.
-
-
Method Detail
-
addRecipient
public void addRecipient(OmemoDevice contactsDevice) throws NoIdentityKeyException, CorruptedOmemoKeyException, UndecidedOmemoIdentityException, UntrustedOmemoIdentityException, java.io.IOException
Add a new recipient device to the message.- Parameters:
contactsDevice- device of the recipient- Throws:
NoIdentityKeyException- if we have no identityKey of that device. Can be fixed by fetching and processing the devices bundle.CorruptedOmemoKeyException- if the identityKey of that device is corrupted.UndecidedOmemoIdentityException- if the user hasn't yet decided whether to trust that device or not.UntrustedOmemoIdentityException- if the user has decided not to trust that device.java.io.IOException- if an I/O error occurred.
-
finish
public OmemoElement finish()
Assemble an OmemoMessageElement from the current state of the builder.- Returns:
- OMEMO element
-
generateKey
public static byte[] generateKey(java.lang.String keyType, int keyLength) throws java.security.NoSuchAlgorithmException
Generate a new AES key used to encrypt the message.- Parameters:
keyType- Key TypekeyLength- Key Length in bit- Returns:
- new AES key
- Throws:
java.security.NoSuchAlgorithmException- if no such algorithm is available.
-
generateIv
public static byte[] generateIv()
Generate a 12 byte initialization vector for AES encryption.- Returns:
- initialization vector
-
-