Skip to content

Instantly share code, notes, and snippets.

@felnne

felnne/main.py Secret

Created June 14, 2018 16:39
Show Gist options
  • Save felnne/b399a0918960696aca5c4324392a72f7 to your computer and use it in GitHub Desktop.
Save felnne/b399a0918960696aca5c4324392a72f7 to your computer and use it in GitHub Desktop.
Cryptography Blowfish decryption
import base64
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers import algorithms, modes, Cipher
key = 'xxx'
iv = b'12345678'
print(type(iv))
inputs = {
'issuing authority': 'xxx'
}
outputs = {}
algorithm = algorithms.Blowfish(key)
decryptor = Cipher(algorithm, mode=modes.CBC(iv), backend=default_backend()).decryptor()
for field, cipher_text in inputs.items():
cipher_text = base64.b64decode(cipher_text)
decryptor.update(cipher_text)
output = decryptor.finalize()
outputs[field] = output.strip()
print(outputs)
@felnne
Copy link
Author

felnne commented Jun 14, 2018

Output when run:

<class 'bytes'>
Traceback (most recent call last):
  File "decrypt-blowflish-string.py", line 31, in <module>
    decryptor = Cipher(algorithm, mode=modes.CBC(iv), backend=default_backend()).decryptor()
  File "/usr/local/lib/python3.6/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 127, in decryptor
    self.algorithm, self.mode
  File "/usr/local/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 271, in create_symmetric_decryption_ctx
    return _CipherContext(self, cipher, mode, _CipherContext._DECRYPT)
  File "/usr/local/lib/python3.6/site-packages/cryptography/hazmat/backends/openssl/ciphers.py", line 110, in __init__
    operation
TypeError: initializer for ctype 'unsigned char *' must be a bytes or list or tuple, not str

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment