TLS Encryption: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
No edit summary
Line 138:
 
return iv[4:] + ciphertext + auth_tag
</source>
 
Decrypting: <br >
Here is an example using TLS_RSA_WITH_AES_128_GCM_SHA256 and the pycryptodome library.
When decrypting a message sent by the server, use the client_write_key and IV and when decrypting a message sent by the client use the server_write_key and IV.
<source lang="python">
nonce = IV + encrypted_data[0:8]
 
cipher = AES.new(key, AES.MODE_GCM, nonce=nonce, mac_len=16)
cipher.update(authenticated_data)
dec = cipher.decrypt_and_verify(encrypted_data[8:24], encrypted_data[24:40])
</source>