public class CryptTool extends Object
Constructor and Description |
---|
CryptTool() |
Modifier and Type | Method and Description |
---|---|
static byte[] |
decrypt(byte[] box,
byte[] privateKey,
byte[] publicKey,
byte[] nonce)
Decrypt an NaCl box using the recipient's private key and the sender's public key.
|
static byte[] |
decryptFileData(byte[] fileData,
byte[] secret)
Decrypt symmetrically encrypted file data.
|
static byte[] |
decryptFileThumbnailData(byte[] fileData,
byte[] secret)
Decrypt symmetrically encrypted file thumbnail data.
|
static ThreemaMessage |
decryptMessage(byte[] box,
byte[] recipientPrivateKey,
byte[] senderPublicKey,
byte[] nonce)
Decrypt a message.
|
static byte[] |
derivePublicKey(byte[] privateKey)
Return the public key that corresponds with a given private key.
|
static EncryptResult |
encrypt(byte[] data,
byte[] privateKey,
byte[] publicKey)
Encrypt data using NaCl asymmetric ("box") encryption.
|
static EncryptResult |
encryptFileData(byte[] data)
Encrypt file data using NaCl symmetric encryption with a random key.
|
static EncryptResult |
encryptFileMessage(EncryptResult encryptResult,
UploadResult uploadResult,
String mimeType,
String fileName,
int fileSize,
UploadResult uploadResultThumbnail,
byte[] senderPrivateKey,
byte[] recipientPublicKey)
Encrypt a file message.
|
static EncryptResult |
encryptFileThumbnailData(byte[] data,
byte[] encryptionKey)
Encrypt file thumbnail data using NaCl symmetric encryption with a random key.
|
static EncryptResult |
encryptImageMessage(EncryptResult encryptResult,
UploadResult uploadResult,
byte[] senderPrivateKey,
byte[] recipientPublicKey)
Encrypt an image message.
|
static EncryptResult |
encryptTextMessage(String text,
byte[] senderPrivateKey,
byte[] recipientPublicKey)
Encrypt a text message.
|
static void |
generateKeyPair(byte[] privateKey,
byte[] publicKey)
Generate a new key pair.
|
static byte[] |
hashEmail(String email)
Hashes an email address for identity lookup.
|
static byte[] |
hashPhoneNo(String phoneNo)
Hashes a phone number for identity lookup.
|
static byte[] |
randomNonce()
Generate a random nonce.
|
public static EncryptResult encryptTextMessage(String text, byte[] senderPrivateKey, byte[] recipientPublicKey)
text
- the text to be encrypted (max. 3500 bytes)senderPrivateKey
- the private key of the sending IDrecipientPublicKey
- the public key of the receiving IDpublic static EncryptResult encryptImageMessage(EncryptResult encryptResult, UploadResult uploadResult, byte[] senderPrivateKey, byte[] recipientPublicKey)
encryptResult
- result of the image encryptionuploadResult
- result of the uploadsenderPrivateKey
- the private key of the sending IDrecipientPublicKey
- the public key of the receiving IDpublic static EncryptResult encryptFileMessage(EncryptResult encryptResult, UploadResult uploadResult, String mimeType, String fileName, int fileSize, UploadResult uploadResultThumbnail, byte[] senderPrivateKey, byte[] recipientPublicKey)
encryptResult
- result of the file data encryptionuploadResult
- result of the uploadmimeType
- MIME type of the filefileName
- File namefileSize
- Size of the file, in bytesuploadResultThumbnail
- result of thumbnail uploadsenderPrivateKey
- Private key of senderrecipientPublicKey
- Public key of recipientpublic static byte[] decrypt(byte[] box, byte[] privateKey, byte[] publicKey, byte[] nonce)
box
- The box to be decryptedprivateKey
- The private key of the recipientpublicKey
- The public key of the sendernonce
- The nonce that was used for encryptionpublic static byte[] decryptFileData(byte[] fileData, byte[] secret)
fileData
- The encrypted file datasecret
- The symmetric key that was used for encryptionpublic static byte[] decryptFileThumbnailData(byte[] fileData, byte[] secret)
fileData
- The encrypted thumbnail datasecret
- The symmetric key that was used for encryptionpublic static ThreemaMessage decryptMessage(byte[] box, byte[] recipientPrivateKey, byte[] senderPublicKey, byte[] nonce) throws MessageParseException
box
- the box to be decryptedrecipientPrivateKey
- the private key of the receiving IDsenderPublicKey
- the public key of the sending IDnonce
- the nonce that was used for the encryptionMessageParseException
public static void generateKeyPair(byte[] privateKey, byte[] publicKey)
privateKey
- is used to return the generated private key (length must be NaCl.PRIVATEKEYBYTES)publicKey
- is used to return the generated public key (length must be NaCl.PUBLICKEYBYTES)public static EncryptResult encrypt(byte[] data, byte[] privateKey, byte[] publicKey)
data
- the data to be encryptedprivateKey
- is used to return the generated private key (length must be NaCl.PRIVATEKEYBYTES)publicKey
- is used to return the generated public key (length must be NaCl.PUBLICKEYBYTES)public static EncryptResult encryptFileData(byte[] data)
data
- the file contents to be encryptedpublic static EncryptResult encryptFileThumbnailData(byte[] data, byte[] encryptionKey)
data
- the file contents to be encryptedpublic static byte[] hashEmail(String email)
email
- the email addresspublic static byte[] hashPhoneNo(String phoneNo)
phoneNo
- the phone numberpublic static byte[] randomNonce()
public static byte[] derivePublicKey(byte[] privateKey)
privateKey
- The private key whose public key should be derivedCopyright © 2015 Threema GmbH, Staldenbachstrasse 11, 8808 Pfäffikon SZ, Schweiz. All rights reserved.