mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
12986b9ce3
commit
19c1d25c24
@ -253,6 +253,11 @@ class CBC:
|
|||||||
return {'iv':first_iv, 'cipherbytes':outputbytes}
|
return {'iv':first_iv, 'cipherbytes':outputbytes}
|
||||||
|
|
||||||
def encrypt(self, plaintext, tag):
|
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))
|
return self.encrypt_bytes(string_to_bytes(plaintext), string_to_bytes(tag) if tag else Uint8Array(0))
|
||||||
|
|
||||||
def decrypt(self, output_from_encrypt, tag):
|
def decrypt(self, output_from_encrypt, tag):
|
||||||
@ -281,7 +286,6 @@ if __name__ == '__main__':
|
|||||||
crypted = cbc.encrypt(text)
|
crypted = cbc.encrypt(text)
|
||||||
decrypted = cbc.decrypt(crypted)
|
decrypted = cbc.decrypt(crypted)
|
||||||
print('Roundtrip:', 'OK' if text is decrypted else 'FAILED')
|
print('Roundtrip:', 'OK' if text is decrypted else 'FAILED')
|
||||||
crypted = cbc.encrypt(text, 'secret')
|
crypted = cbc.encrypt(text, 'secret-tag')
|
||||||
decrypted = cbc.decrypt(crypted, 'secret')
|
decrypted = cbc.decrypt(crypted, 'secret-tag')
|
||||||
print('Roundtrip with tag:', 'OK' if text is decrypted else 'FAILED')
|
print('Roundtrip with tag:', 'OK' if text is decrypted else 'FAILED')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user