@@ -51,24 +51,18 @@ by itself:
51
51
from os import urandom
52
52
53
53
key = urandom(32 ) # key is 32 bytes
54
- nonce = ' thisisanonce' # nonce is 12 bytes (DO NOT REUSE A NONCE WITH THE SAME KEY)
55
- message = ' Some message to be encrypted'
56
- additional_data = ' Some additional data' # this will not be encrypted but will be verified for integrity
54
+ nonce = b ' thisisanonce' # nonce is 12 bytes (DO NOT REUSE A NONCE WITH THE SAME KEY)
55
+ message = b ' Some message to be encrypted'
56
+ additional_data = b ' Some additional data' # this will not be encrypted but will be verified for integrity
57
57
58
58
# encryption
59
59
ciphertext, mac = aead.encrypt_and_tag(key, nonce, message, additional_data)
60
60
61
61
# decryption (which yields plaintext == message)
62
62
plaintext = aead.verify_and_decrypt(key, nonce, ciphertext, mac, additional_data)
63
63
64
- Notes on Python 2 vs 3
65
- ----------------------
66
64
67
- In python2 encryption and decryption and tagging will return :code: `str ` data while in python3 they will return
68
- :code: `bytes ` data. This is consistent with how much of the python library operates between the two versions (e.g.
69
- see :code: `binascii.unhexlify `). This can lead to some strange behavior if e.g. you encrypt a :code: `str ` value in
70
- python3 and, after decrypting, your decrypted value does not match your original value because you got :code: `bytes `
71
- back from the decryption. If the returned type is undesirable it is of course always possible to convert between
72
- :code: `bytes ` and :code: `str ` as needed.
65
+ Note that all operations in this package work on bytes. You'll need to call e.g. :code: `encode() ` on strings
66
+ before passing them as arguments.
73
67
74
68
.. _RFC7539 : https://tools.ietf.org/html/rfc7539
0 commit comments