From 19c1d25c2417c6dd9dd578249df985b73ba04f74 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 21 Mar 2016 21:52:45 +0530 Subject: [PATCH] ... --- src/pyj/aes.pyj | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pyj/aes.pyj b/src/pyj/aes.pyj index 8391eba28c..aff1ee5d32 100644 --- a/src/pyj/aes.pyj +++ b/src/pyj/aes.pyj @@ -253,6 +253,11 @@ class CBC: return {'iv':first_iv, 'cipherbytes':outputbytes} def encrypt(self, plaintext, tag): + # Encrypt the plaintext (a string) returning an object that contains + # the used initialization vector and the encrypted bytes (as + # Uint8Arrays). If the optional tag (a string) is present, it is also + # encrypted along with plaintext.It can be used to ensure message integrity. + # See the __main__ block at the bottom of this file for example usage. return self.encrypt_bytes(string_to_bytes(plaintext), string_to_bytes(tag) if tag else Uint8Array(0)) def decrypt(self, output_from_encrypt, tag): @@ -281,7 +286,6 @@ if __name__ == '__main__': crypted = cbc.encrypt(text) decrypted = cbc.decrypt(crypted) print('Roundtrip:', 'OK' if text is decrypted else 'FAILED') - crypted = cbc.encrypt(text, 'secret') - decrypted = cbc.decrypt(crypted, 'secret') + crypted = cbc.encrypt(text, 'secret-tag') + decrypted = cbc.decrypt(crypted, 'secret-tag') print('Roundtrip with tag:', 'OK' if text is decrypted else 'FAILED') -