Package ch.threema.apitool.helpers
Class E2EHelper
java.lang.Object
ch.threema.apitool.helpers.E2EHelper
Helper to handle Threema end-to-end encryption.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionreceiveMessage(String threemaId, String messageId, byte[] box, byte[] nonce, Path outputFolder) Decrypt a Message and download the blobs of the Message (e.g. image or file)sendBallotCreateMessage(String threemaId, byte[] ballotId, String description, State state, VotingMode votingMode, ResultsDisclosureType resultsDisclosureType, DisplayMode displayMode, List<BallotChoice> choices, List<String> participants) Encrypt a ballot create message and send it to the given recipient.sendBallotVoteMessage(String threemaId, byte[] creator, byte[] ballotId, List<VoteChoice> votes) Encrypt a ballot vote message and send it to the given recipient.sendDeliveryReceipt(String threemaId, List<MessageId> ackedMessageIds, DeliveryReceipt.Type receiptType) Encrypt a delivery receipt and send it to the original sender.sendFileMessage(String threemaId, File fileMessageFile) Encrypt a file message and send it to the given recipient.sendFileMessage(String threemaId, File fileMessageFile, File thumbnailMessagePath, String caption) Encrypt a file message and send it to the given recipient.sendFileMessage(String threemaId, File fileMessageFile, File thumbnailMessagePath, String caption, FileRenderingType renderingType) Encrypt a file message and send it to the given recipient.sendFileMessage(String threemaId, File fileMessageFile, File thumbnailMessageFile, String caption, FileRenderingType renderingType, String correlationId, Map<String, Object> metadata) Encrypt a file message and send it to the given recipient.ApiResponse<org.json.JSONArray> sendGroupBallotCreateMessage(List<String> threemaIds, GroupId groupId, byte[] ballotId, String description, State state, VotingMode votingMode, ResultsDisclosureType resultsDisclosureType, DisplayMode displayMode, List<BallotChoice> choices, List<String> participants) Encrypt a ballot create message and send it to the given group.ApiResponse<org.json.JSONArray> sendGroupBallotVoteMessage(List<String> threemaIds, byte[] creator, GroupId groupId, byte[] ballotId, List<VoteChoice> votes) Encrypt a ballot vote message and send it to the given group.ApiResponse<org.json.JSONArray> Encrypt a group create message and send it to the given group.ApiResponse<org.json.JSONArray> sendGroupDeletePhotoMessage(List<String> threemaIds, GroupId groupId) Encrypt a group delete photo message and send it to the given group.ApiResponse<org.json.JSONArray> sendGroupDeliveryReceipt(List<String> threemaIds, GroupId groupId, List<MessageId> ackedMessageIds, DeliveryReceipt.Type receiptType) Encrypt a group delivery receipt and send it to all group membersApiResponse<org.json.JSONArray> sendGroupFileMessage(List<String> threemaId, GroupId groupId, File fileMessageFile) Encrypt a file message and send it to the given group.ApiResponse<org.json.JSONArray> sendGroupFileMessage(List<String> threemaId, GroupId groupId, File fileMessageFile, File thumbnailMessageFile, String caption, FileRenderingType renderingType) Encrypt a file message and send it to the given group.ApiResponse<org.json.JSONArray> sendGroupFileMessage(List<String> threemaIds, GroupId groupId, File fileMessageFile, File thumbnailMessageFile, String caption, FileRenderingType renderingType, String correlationId, Map<String, Object> metadata) Encrypt a file message and send it to the given group.ApiResponse<org.json.JSONArray> sendGroupLeaveMessage(List<String> threemaIds, GroupId groupId) Encrypt a group leave message and send it to the given group.ApiResponse<org.json.JSONArray> sendGroupLocationMessage(List<String> threemaIds, GroupId groupId, String lat, String lng, Float accuracy, String poiName, String poiAddress) Encrypt a file message and send it to the given group.ApiResponse<org.json.JSONArray> sendGroupLocationMessage(List<String> threemaIds, GroupId groupId, String lat, String lng, String poiName, String poiAddress) Encrypt a file message and send it to the given group.ApiResponse<org.json.JSONArray> sendGroupRenameMessage(List<String> threemaIds, GroupId groupId, String newGroupName) Encrypt a group rename message and send it to the given group.ApiResponse<org.json.JSONArray> sendGroupRequestSyncMsg(List<String> threemaIds, GroupId groupId) Encrypt a group request sync message and send it to the given group.ApiResponse<org.json.JSONArray> sendGroupSetPhotoMessage(List<String> threemaIds, GroupId groupId, File groupPhotoInJpg) Encrypt a group set photo message and send it to the given group.ApiResponse<org.json.JSONArray> sendGroupTextMessage(List<String> threemaIds, GroupId groupId, String text) Encrypt a file message and send it to the given group.sendImageMessage(String threemaId, String imageFilePath) Deprecated.sendLocationMessage(String threemaId, String lat, String lng, Float accuracy, String poiName, String poiAddress) Encrypt a text message and send it to the given recipient.Encrypt a text message and send it to the given recipient.sendTextMessage(String threemaId, String text) Encrypt a text message and send it to the given recipient.
-
Constructor Details
-
E2EHelper
-
-
Method Details
-
sendTextMessage
Encrypt a text message and send it to the given recipient.- Parameters:
threemaId- target Threema IDtext- the text to send- Returns:
- generated message ID
- Throws:
Exception
-
sendLocationMessage
public ApiResponse<String> sendLocationMessage(String threemaId, String lat, String lng, String poiName, String poiAddress) throws Exception Encrypt a text message and send it to the given recipient.- Parameters:
threemaId- target Threema IDlat- the location latitudelng- the location longitudepoiName- the poi namepoiAddress- the location address- Returns:
- generated message ID
- Throws:
Exception
-
sendLocationMessage
public ApiResponse<String> sendLocationMessage(String threemaId, String lat, String lng, Float accuracy, String poiName, String poiAddress) throws Exception Encrypt a text message and send it to the given recipient.- Parameters:
threemaId- target Threema IDlat- the location latitudelng- the location longitudeaccuracy- the location accuracypoiName- the poi namepoiAddress- the location address- Returns:
- generated message ID
- Throws:
Exception
-
sendGroupTextMessage
public ApiResponse<org.json.JSONArray> sendGroupTextMessage(List<String> threemaIds, GroupId groupId, String text) throws InvalidKeyException, IOException, ApiException Encrypt a file message and send it to the given group. The thumbnailMessagePath can be null.- Parameters:
threemaIds- target Threema IDsgroupId- target Threema Group IDtext- Message text- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionIOExceptionApiException
-
sendGroupLocationMessage
public ApiResponse<org.json.JSONArray> sendGroupLocationMessage(List<String> threemaIds, GroupId groupId, String lat, String lng, String poiName, String poiAddress) throws InvalidKeyException, IOException, ApiException Encrypt a file message and send it to the given group. The thumbnailMessagePath can be null.- Parameters:
threemaIds- target Threema IDsgroupId- target Threema Group IDlat- The geographic latitudelng- The geographic longitudepoiName- The location namepoiAddress- The location address- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionIOExceptionApiException
-
sendGroupLocationMessage
public ApiResponse<org.json.JSONArray> sendGroupLocationMessage(List<String> threemaIds, GroupId groupId, String lat, String lng, Float accuracy, String poiName, String poiAddress) throws InvalidKeyException, IOException, ApiException Encrypt a file message and send it to the given group. The thumbnailMessagePath can be null.- Parameters:
threemaIds- target Threema IDsgroupId- target Threema Group IDlat- The geographic latitudelng- The geographic longitudeaccuracy- The location accuracypoiName- The location namepoiAddress- The location address- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionIOExceptionApiException
-
sendImageMessage
@Deprecated public ApiResponse<String> sendImageMessage(String threemaId, String imageFilePath) throws NotAllowedException, IOException, InvalidKeyException, ApiException Deprecated.Encrypt an image message and send it to the given recipient.- Parameters:
threemaId- target Threema IDimageFilePath- path to read image data from- Returns:
- generated message ID
- Throws:
NotAllowedExceptionIOExceptionInvalidKeyExceptionApiException
-
sendFileMessage
public ApiResponse<String> sendFileMessage(String threemaId, File fileMessageFile) throws InvalidKeyException, IOException, NotAllowedException, ApiException Encrypt a file message and send it to the given recipient. The thumbnailMessagePath can be null.- Parameters:
threemaId- target Threema IDfileMessageFile- the file to be sent- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionIOExceptionNotAllowedExceptionApiException
-
sendFileMessage
public ApiResponse<String> sendFileMessage(String threemaId, File fileMessageFile, File thumbnailMessagePath, String caption) throws InvalidKeyException, IOException, NotAllowedException, ApiException Encrypt a file message and send it to the given recipient. The thumbnailMessagePath can be null.- Parameters:
threemaId- target Threema IDfileMessageFile- the file to be sentthumbnailMessagePath- file for thumbnail; if not set, no thumbnail will be sentcaption- caption for the file message; if not set, no caption will be attached- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionIOExceptionNotAllowedExceptionApiException
-
sendFileMessage
public ApiResponse<String> sendFileMessage(String threemaId, File fileMessageFile, File thumbnailMessagePath, String caption, FileRenderingType renderingType) throws InvalidKeyException, IOException, NotAllowedException, ApiException Encrypt a file message and send it to the given recipient. The thumbnailMessagePath can be null.- Parameters:
threemaId- target Threema IDfileMessageFile- the file to be sentthumbnailMessagePath- file for thumbnail; if not set, no thumbnail will be sentcaption- caption for the file message; if not set, no caption will be attachedrenderingType- file rendering type- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionIOExceptionNotAllowedExceptionApiException
-
sendFileMessage
public ApiResponse<String> sendFileMessage(String threemaId, File fileMessageFile, File thumbnailMessageFile, String caption, FileRenderingType renderingType, String correlationId, Map<String, Object> metadata) throws InvalidKeyException, IOException, NotAllowedException, ApiExceptionEncrypt a file message and send it to the given recipient. The thumbnailMessageFile can be null.- Parameters:
threemaId- target Threema IDfileMessageFile- the file to be sentthumbnailMessageFile- file for thumbnail; if not set, no thumbnail will be sentcaption- caption for the file message; if not set, no caption will be attachedrenderingType- file rendering typecorrelationId- media correlation IDmetadata- FileMessage metadata- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionIOExceptionNotAllowedExceptionApiException
-
sendBallotCreateMessage
public ApiResponse<String> sendBallotCreateMessage(String threemaId, byte[] ballotId, String description, State state, VotingMode votingMode, ResultsDisclosureType resultsDisclosureType, DisplayMode displayMode, List<BallotChoice> choices, List<String> participants) throws InvalidKeyException, ApiException, IOException Encrypt a ballot create message and send it to the given recipient.- Parameters:
threemaId- target Threema IDballotId- The poll ballot identifierdescription- The group poll descriptionstate- The group poll statevotingMode- The voting moderesultsDisclosureType- The poll results disclosure typedisplayMode- The display modechoices- The available vote choicesparticipants- The poll participants- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionApiExceptionIOException
-
sendBallotVoteMessage
public ApiResponse<String> sendBallotVoteMessage(String threemaId, byte[] creator, byte[] ballotId, List<VoteChoice> votes) throws InvalidKeyException, ApiException, IOException Encrypt a ballot vote message and send it to the given recipient.- Parameters:
threemaId- target Threema IDcreator- Poll creatorballotId- the poll ballot identifiervotes- the group poll votes- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionApiExceptionIOException
-
sendGroupFileMessage
public ApiResponse<org.json.JSONArray> sendGroupFileMessage(List<String> threemaId, GroupId groupId, File fileMessageFile) throws InvalidKeyException, IOException, NotAllowedException, ApiException Encrypt a file message and send it to the given group. The thumbnailMessagePath can be null.- Parameters:
threemaId- target threema IDgroupId- target Threema Group IDfileMessageFile- the file to be sent- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionIOExceptionNotAllowedExceptionApiException
-
sendGroupFileMessage
public ApiResponse<org.json.JSONArray> sendGroupFileMessage(List<String> threemaId, GroupId groupId, File fileMessageFile, File thumbnailMessageFile, String caption, FileRenderingType renderingType) throws InvalidKeyException, IOException, NotAllowedException, ApiException Encrypt a file message and send it to the given group. The thumbnailMessagePath can be null.- Parameters:
threemaId- target threema IDgroupId- target Threema Group IDfileMessageFile- the file to be sentthumbnailMessageFile- file for thumbnail; if not set, no thumbnail will be sentcaption- caption for the file message; if not set, no caption will be attachedrenderingType- file rendering type- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionIOExceptionNotAllowedExceptionApiException
-
sendGroupFileMessage
public ApiResponse<org.json.JSONArray> sendGroupFileMessage(List<String> threemaIds, GroupId groupId, File fileMessageFile, File thumbnailMessageFile, String caption, FileRenderingType renderingType, String correlationId, Map<String, Object> metadata) throws InvalidKeyException, IOException, ApiExceptionEncrypt a file message and send it to the given group. The thumbnailMessageFile can be null.- Parameters:
threemaIds- target Threema IDsgroupId- target Threema Group IDfileMessageFile- the file to be sentthumbnailMessageFile- file for thumbnail; if not set, no thumbnail will be sentcaption- caption for the file message; if not set, no caption will be attachedrenderingType- file rendering typecorrelationId- media correlation IDmetadata- FileMessage metadata- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionIOExceptionApiException
-
sendGroupBallotCreateMessage
public ApiResponse<org.json.JSONArray> sendGroupBallotCreateMessage(List<String> threemaIds, GroupId groupId, byte[] ballotId, String description, State state, VotingMode votingMode, ResultsDisclosureType resultsDisclosureType, DisplayMode displayMode, List<BallotChoice> choices, List<String> participants) throws InvalidKeyException, ApiException, IOException Encrypt a ballot create message and send it to the given group.- Parameters:
groupId- target Threema Group IDballotId- The poll ballot identifierdescription- The group poll descriptionstate- The group poll statevotingMode- The voting moderesultsDisclosureType- The poll results disclosure typedisplayMode- The display modechoices- The available vote choicesparticipants- The poll participants- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionApiExceptionIOException
-
sendGroupBallotVoteMessage
public ApiResponse<org.json.JSONArray> sendGroupBallotVoteMessage(List<String> threemaIds, byte[] creator, GroupId groupId, byte[] ballotId, List<VoteChoice> votes) throws InvalidKeyException, ApiException, IOException Encrypt a ballot vote message and send it to the given group.- Parameters:
threemaIds- target Threema IDscreator- Poll creatorgroupId- target Threema Group IDballotId- the poll ballot identifiervotes- the group poll state- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionApiExceptionIOException
-
sendDeliveryReceipt
public ApiResponse<String> sendDeliveryReceipt(String threemaId, List<MessageId> ackedMessageIds, DeliveryReceipt.Type receiptType) throws InvalidKeyException, ApiException, IOException Encrypt a delivery receipt and send it to the original sender.- Parameters:
threemaId- target Threema IDackedMessageIds- the acknowledged message idsreceiptType- the delivery receipt type- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionApiExceptionIOException
-
sendGroupDeliveryReceipt
public ApiResponse<org.json.JSONArray> sendGroupDeliveryReceipt(List<String> threemaIds, GroupId groupId, List<MessageId> ackedMessageIds, DeliveryReceipt.Type receiptType) throws InvalidKeyException, ApiException, IOException Encrypt a group delivery receipt and send it to all group members- Parameters:
threemaIds- target Threema IDsgroupId- the group identifierackedMessageIds- the acknowledged message idsreceiptType- the delivery receipt type- Returns:
- generated message IDs
- Throws:
InvalidKeyExceptionApiExceptionIOException
-
sendGroupSetPhotoMessage
public ApiResponse<org.json.JSONArray> sendGroupSetPhotoMessage(List<String> threemaIds, GroupId groupId, File groupPhotoInJpg) throws InvalidKeyException, ApiException, IOException Encrypt a group set photo message and send it to the given group.- Parameters:
threemaIds- target Threema IDsgroupId- target Threema Group IDgroupPhotoInJpg- the new jpg image- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionApiExceptionIOException
-
sendGroupDeletePhotoMessage
public ApiResponse<org.json.JSONArray> sendGroupDeletePhotoMessage(List<String> threemaIds, GroupId groupId) throws InvalidKeyException, ApiException, IOException Encrypt a group delete photo message and send it to the given group.- Parameters:
threemaIds- target Threema IDsgroupId- target Threema Group ID- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionApiExceptionIOException
-
sendGroupCreateMessage
public ApiResponse<org.json.JSONArray> sendGroupCreateMessage(List<String> threemaIds, List<String> members, GroupId groupId) throws InvalidKeyException, ApiException, IOException Encrypt a group create message and send it to the given group.- Parameters:
members- target Threema IDsgroupId- target Threema Group ID- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionApiExceptionIOException
-
sendGroupRequestSyncMsg
public ApiResponse<org.json.JSONArray> sendGroupRequestSyncMsg(List<String> threemaIds, GroupId groupId) throws InvalidKeyException, ApiException, IOException Encrypt a group request sync message and send it to the given group.- Parameters:
threemaIds- target Threema IDsgroupId- target Threema Group ID- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionApiExceptionIOException
-
sendGroupRenameMessage
public ApiResponse<org.json.JSONArray> sendGroupRenameMessage(List<String> threemaIds, GroupId groupId, String newGroupName) throws InvalidKeyException, ApiException, IOException Encrypt a group rename message and send it to the given group.- Parameters:
threemaIds- target Threema IDsgroupId- target Threema Group IDnewGroupName- the new group name- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionApiExceptionIOException
-
sendGroupLeaveMessage
public ApiResponse<org.json.JSONArray> sendGroupLeaveMessage(List<String> threemaIds, GroupId groupId) throws InvalidKeyException, ApiException, IOException Encrypt a group leave message and send it to the given group.- Parameters:
threemaIds- target Threema IDsgroupId- target Threema Group ID- Returns:
- generated message ID
- Throws:
InvalidKeyExceptionApiExceptionIOException
-
receiveMessage
public E2EHelper.ReceiveMessageResult receiveMessage(String threemaId, String messageId, byte[] box, byte[] nonce, Path outputFolder) throws IOException, InvalidKeyException, MessageParseException, ApiException Decrypt a Message and download the blobs of the Message (e.g. image or file)- Parameters:
threemaId- Threema ID of the sendermessageId- Message IDbox- Encrypted box data of the file/image messagenonce- Nonce that was used for message encryptionoutputFolder- Output folder for storing decrypted images/files- Returns:
- result of message reception
- Throws:
IOExceptionInvalidKeyExceptionMessageParseExceptionApiException
-