As an optional feature, the TeamSpeak 3 SDK allows users to implement custom encryption and decryption for all network traffic. Custom encryption replaces the default AES encryption implemented by the TeamSpeak 3 SDK. A possible reason to apply own encryption might be to make ones TeamSpeak 3 client/server incompatible to other SDK implementations.
Custom encryption must be implemented the same way in both the client and server.
Note | |
---|---|
If you do not want to use this feature, just don't implement the two encryption callbacks. |
To encrypt outgoing data, implement the callback:
void onCustomPacketEncryptEvent( | dataToSend, | á |
á | sizeOfData) ; | á |
char** dataToSend
;unsigned int* sizeOfData
;Parameters
dataToSend
Pointer to an array with the outgoing data to be encrypted.
Apply your custom encryption to the data array. If the encrypted data is smaller than sizeOfData, write your encrypted data into the existing memory of dataToSend. If your encrypted data is larger, you need to allocate memory and redirect the pointer dataToSend. You need to take care of freeing your own allocated memory yourself. The memory allocated by the SDK, to which dataToSend is originally pointing to, must not be freed.
sizeOfData
Pointer to an integer value containing the size of the data array.
To decrypt incoming data, implement the callback:
void onCustomPacketDecryptEvent( | dataReceived, | á |
á | dataReceivedSize) ; | á |
char** dataReceived
;unsigned int* dataReceivedSize
;Parameters
dataReceived
Pointer to an array with the received data to be decrypted.
Apply your custom decryption to the data array. If the decrypted data is smaller than dataReceivedSize, write your decrypted data into the existing memory of dataReceived. If your decrypted data is larger, you need to allocate memory and redirect the pointer dataReceived. You need to take care of freeing your own allocated memory yourself. The memory allocated by the SDK, to which dataReceived is originally pointing to, must not be freed.
dataReceivedSize
Pointer to an integer value containing the size of the data array.
Example code implementing a very simple XOR custom encryption and decryption (also see the SDK examples):
void onCustomPacketEncryptEvent(char** dataToSend, unsigned int* sizeOfData) { unsigned int i; for(i = 0; i < *sizeOfData; i++) { (*dataToSend)[i] ^= CUSTOM_CRYPT_KEY; } } void onCustomPacketDecryptEvent(char** dataReceived, unsigned int* dataReceivedSize) { unsigned int i; for(i = 0; i < *dataReceivedSize; i++) { (*dataReceived)[i] ^= CUSTOM_CRYPT_KEY; } }