Constants

TYPE_SODIUM

TYPE_SODIUM

TYPE_SALT

TYPE_SALT

FILE_NONCE

FILE_NONCE

FILE_THUMBNAIL_NONCE

FILE_THUMBNAIL_NONCE

MESSAGE_ID_LEN

MESSAGE_ID_LEN

BLOB_ID_LEN

BLOB_ID_LEN

IMAGE_FILE_SIZE_LEN

IMAGE_FILE_SIZE_LEN

IMAGE_NONCE_LEN

IMAGE_NONCE_LEN

EMAIL_HMAC_KEY

EMAIL_HMAC_KEY

PHONENO_HMAC_KEY

PHONENO_HMAC_KEY

Properties

Methods

createInstance()

createInstance(string  $type) : null|\Threema\MsgApi\Tools\CryptTool

Parameters

string $type

Returns

null|\Threema\MsgApi\Tools\CryptTool

null on unknown type

encryptMessageText()

encryptMessageText(string  $text, string  $senderPrivateKey, string  $recipientPublicKey, string  $nonce) : string

Encrypt a text message.

Parameters

string $text

the text to be encrypted (max. 3500 bytes)

string $senderPrivateKey

the private key of the sending ID

string $recipientPublicKey

the public key of the receiving ID

string $nonce

the nonce to be used for the encryption (usually 24 random bytes)

Returns

string —

encrypted box

encryptImageMessage()

encryptImageMessage(\Threema\MsgApi\Commands\Results\UploadFileResult  $uploadFileResult, \Threema\MsgApi\Tools\EncryptResult  $encryptResult, string  $senderPrivateKey, string  $recipientPublicKey, string  $nonce) : string

Parameters

\Threema\MsgApi\Commands\Results\UploadFileResult $uploadFileResult

the result of the upload

\Threema\MsgApi\Tools\EncryptResult $encryptResult

the result of the image encryption

string $senderPrivateKey

the private key of the sending ID (as binary)

string $recipientPublicKey

the public key of the receiving ID (as binary)

string $nonce

the nonce to be used for the encryption (usually 24 random bytes)

Returns

string

encryptFileMessage()

encryptFileMessage(\Threema\MsgApi\Commands\Results\UploadFileResult  $uploadFileResult, \Threema\MsgApi\Tools\EncryptResult  $encryptResult, \Threema\MsgApi\Commands\Results\UploadFileResult  $thumbnailUploadFileResult = null, \Threema\MsgApi\Tools\FileAnalysisResult  $fileAnalysisResult,   $senderPrivateKey,   $recipientPublicKey,   $nonce) 

Parameters

\Threema\MsgApi\Commands\Results\UploadFileResult $uploadFileResult
\Threema\MsgApi\Tools\EncryptResult $encryptResult
\Threema\MsgApi\Commands\Results\UploadFileResult $thumbnailUploadFileResult
\Threema\MsgApi\Tools\FileAnalysisResult $fileAnalysisResult
$senderPrivateKey
$recipientPublicKey
$nonce

decryptMessage()

decryptMessage(string  $box, string  $recipientPrivateKey, string  $senderPublicKey, string  $nonce) : \Threema\MsgApi\Messages\ThreemaMessage

Parameters

string $box
string $recipientPrivateKey
string $senderPublicKey
string $nonce

Throws

\Threema\MsgApi\Exceptions\BadMessageException
\Threema\MsgApi\Exceptions\DecryptionFailedException
\Threema\MsgApi\Exceptions\UnsupportedMessageTypeException

Returns

\Threema\MsgApi\Messages\ThreemaMessage

the decrypted message

generateKeyPair()

generateKeyPair() : \Threema\Core\KeyPair

Generate a new key pair.

Returns

\Threema\Core\KeyPair

the new key pair

hashEmail()

hashEmail(string  $email) : string

Hashes an email address for identity lookup.

Parameters

string $email

the email address

Returns

string —

the email hash (hex)

hashPhoneNo()

hashPhoneNo(string  $phoneNo) : string

Hashes an phone number address for identity lookup.

Parameters

string $phoneNo

the phone number (in E.164 format, no leading +)

Returns

string —

the phone number hash (hex)

randomNonce()

randomNonce() : string

Generate a random nonce.

Returns

string —

random nonce

symmetricKey()

symmetricKey() : mixed

Generate a symmetric key

Returns

mixed

derivePublicKey()

derivePublicKey(string  $privateKey) : string

Derive the public key

Parameters

string $privateKey

in binary

Returns

string —

public key as binary

isSupported()

isSupported() : boolean

Check if implementation supported

Returns

boolean

validate()

validate() : boolean

Validate crypt tool

Throws

\Threema\Core\Exception

Returns

boolean

decryptFile()

decryptFile(string  $data, string  $key) : null|string

Parameters

string $data

as binary

string $key

as binary

Returns

null|string

encryptFileThumbnail()

encryptFileThumbnail(string  $data, string  $key) : \Threema\MsgApi\Tools\EncryptResult

Parameters

string $data
string $key

Returns

\Threema\MsgApi\Tools\EncryptResult

decryptFileThumbnail()

decryptFileThumbnail(  $data,   $key) 

Parameters

$data
$key

encryptImage()

encryptImage(string  $imageData, string  $privateKey, string  $publicKey) : \Threema\MsgApi\Tools\EncryptResult

Parameters

string $imageData
string $privateKey

as binary

string $publicKey

as binary

Returns

\Threema\MsgApi\Tools\EncryptResult

decryptImage()

decryptImage(string  $data, string  $publicKey, string  $privateKey, string  $nonce) : string

Parameters

string $data

as binary

string $publicKey

as binary

string $privateKey

as binary

string $nonce

as binary

Returns

string

__toString()

__toString() 

getName()

getName() : string

Name of the CryptTool

Returns

string

getDescription()

getDescription() : string

Description of the CryptTool

Returns

string

encryptImageData()

encryptImageData(  $imageData,   $recipientPublicKey,   $senderPrivateKey) : \Threema\MsgApi\Tools\EncryptResult

Parameters

$imageData
$recipientPublicKey
$senderPrivateKey

Throws

\Threema\Core\Exception

Returns

\Threema\MsgApi\Tools\EncryptResult

__construct()

__construct() 

makeBox()

makeBox(string  $data, string  $nonce, string  $senderPrivateKey, string  $recipientPublicKey) : string

make a box

Parameters

string $data
string $nonce
string $senderPrivateKey
string $recipientPublicKey

Returns

string —

encrypted box

makeSecretBox()

makeSecretBox(string  $data, string  $nonce, string  $key) : string

make a secret box

Parameters

string $data
string $nonce
string $key

Returns

string —

encrypted secret box

openBox()

openBox(string  $box, string  $recipientPrivateKey, string  $senderPublicKey, string  $nonce) : null|string

decrypt a box

Parameters

string $box

as binary

string $recipientPrivateKey

as binary

string $senderPublicKey

as binary

string $nonce

as binary

Returns

null|string

openSecretBox()

openSecretBox(string  $box, string  $nonce, string  $key) : string

decrypt a secret box

Parameters

string $box

as binary

string $nonce

as binary

string $key

as binary

Returns

string —

as binary

createRandom()

createRandom(integer  $size) : string

Parameters

integer $size

Returns

string

generatePadBytes()

generatePadBytes() : integer

determine random amount of PKCS7 padding

Returns

integer