coleifer / beefish Goto Github PK
View Code? Open in Web Editor NEWsimple file encryption with pycrypto
License: MIT License
simple file encryption with pycrypto
License: MIT License
Thanks!
C:\Users\USER>pip install -e git+git://github.com/coleifer/beefish.git#egg=beefish
Obtaining beefish from git+git://github.com/coleifer/beefish.git#egg=beefish
Cloning git://github.com/coleifer/beefish.git to c:\users\user\src\beefish
Running command git clone --filter=blob:none --quiet git://github.com/coleifer/beefish.git 'C:\Users\USER\src\beefish'
fatal: remote error:
The unauthenticated git protocol on port 9418 is no longer supported.
Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information.
error: subprocess-exited-with-error
× git clone --filter=blob:none --quiet git://github.com/coleifer/beefish.git 'C:\Users\USER\src\beefish' did not run successfully.
│ exit code: 128
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× git clone --filter=blob:none --quiet git://github.com/coleifer/beefish.git 'C:\Users\USER\src\beefish' did not run successfully.
│ exit code: 128
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
C:\Users\USER>
It produces different results every time I run it with the same input and key.
Also I can't decrypt the file on another machine.
Also I found the test has failed.
test_chunk_sizes (__main__.TestEncryptDecrypt) ... ERROR
test_encrypt_decrypt (__main__.TestEncryptDecrypt) ... ERROR
test_key (__main__.TestEncryptDecrypt) ... ERROR
test_stringio (__main__.TestEncryptDecrypt) ... ERROR
test_chunk_sizes (__main__.TestEncryptDecryptAES) ... ok
test_encrypt_decrypt (__main__.TestEncryptDecryptAES) ... ok
test_key (__main__.TestEncryptDecryptAES) ... ok
test_stringio (__main__.TestEncryptDecryptAES) ... ok
======================================================================
ERROR: test_chunk_sizes (__main__.TestEncryptDecrypt)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 191, in test_chunk_sizes
buf, decrypted = self.crypt_data(num_bytes, b'a', chunk_size=i)
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 163, in crypt_data
self.cipher_type)
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 122, in encrypt_file
encrypt(in_fh, out_fh, key, chunk_size, cipher_type)
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 76, in encrypt
cipher = get_cipher(key, iv)
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 48, in get_blowfish_cipher
return Blowfish.new(key, Blowfish.MODE_CBC, iv)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 146, in new
return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/__init__.py", line 79, in _create_cipher
return modes[mode](factory, **kwargs)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/_mode_cbc.py", line 234, in _create_cbc_cipher
cipher_state = factory._create_base_cipher(kwargs)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 77, in _create_base_cipher
result = start_operation(c_uint8_ptr(key),
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Util/_raw_api.py", line 109, in c_uint8_ptr
raise TypeError("Object type %s cannot be passed to C code" % type(data))
TypeError: Object type <class 'str'> cannot be passed to C code
======================================================================
ERROR: test_encrypt_decrypt (__main__.TestEncryptDecrypt)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 178, in test_encrypt_decrypt
encrypt_flow(b'a')
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 175, in encrypt_flow
buf, decrypted = self.crypt_data(i, ch)
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 163, in crypt_data
self.cipher_type)
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 122, in encrypt_file
encrypt(in_fh, out_fh, key, chunk_size, cipher_type)
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 76, in encrypt
cipher = get_cipher(key, iv)
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 48, in get_blowfish_cipher
return Blowfish.new(key, Blowfish.MODE_CBC, iv)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 146, in new
return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/__init__.py", line 79, in _create_cipher
return modes[mode](factory, **kwargs)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/_mode_cbc.py", line 234, in _create_cbc_cipher
cipher_state = factory._create_base_cipher(kwargs)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 77, in _create_base_cipher
result = start_operation(c_uint8_ptr(key),
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Util/_raw_api.py", line 109, in c_uint8_ptr
raise TypeError("Object type %s cannot be passed to C code" % type(data))
TypeError: Object type <class 'str'> cannot be passed to C code
======================================================================
ERROR: test_key (__main__.TestEncryptDecrypt)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 184, in test_key
buf, decrypted = self.crypt_data(128, b'a', self.key, self.key+'x')
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 163, in crypt_data
self.cipher_type)
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 122, in encrypt_file
encrypt(in_fh, out_fh, key, chunk_size, cipher_type)
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 76, in encrypt
cipher = get_cipher(key, iv)
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 48, in get_blowfish_cipher
return Blowfish.new(key, Blowfish.MODE_CBC, iv)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 146, in new
return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/__init__.py", line 79, in _create_cipher
return modes[mode](factory, **kwargs)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/_mode_cbc.py", line 234, in _create_cbc_cipher
cipher_state = factory._create_base_cipher(kwargs)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 77, in _create_base_cipher
result = start_operation(c_uint8_ptr(key),
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Util/_raw_api.py", line 109, in c_uint8_ptr
raise TypeError("Object type %s cannot be passed to C code" % type(data))
TypeError: Object type <class 'str'> cannot be passed to C code
======================================================================
ERROR: test_stringio (__main__.TestEncryptDecrypt)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 203, in test_stringio
encrypt(in_buf, out_buf, self.key, i, self.cipher_type)
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 76, in encrypt
cipher = get_cipher(key, iv)
File "/Users/chengguangnan/anaconda3/bin/beefish.py", line 48, in get_blowfish_cipher
return Blowfish.new(key, Blowfish.MODE_CBC, iv)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 146, in new
return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/__init__.py", line 79, in _create_cipher
return modes[mode](factory, **kwargs)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/_mode_cbc.py", line 234, in _create_cbc_cipher
cipher_state = factory._create_base_cipher(kwargs)
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Cipher/Blowfish.py", line 77, in _create_base_cipher
result = start_operation(c_uint8_ptr(key),
File "/Users/chengguangnan/anaconda3/lib/python3.6/site-packages/Crypto/Util/_raw_api.py", line 109, in c_uint8_ptr
raise TypeError("Object type %s cannot be passed to C code" % type(data))
TypeError: Object type <class 'str'> cannot be passed to C code
----------------------------------------------------------------------
Ran 8 tests in 0.262s
FAILED (errors=4)
The dependency pycrypto
for this package has been discontinued, and they recommend pycryptodome
as a drop-in replacement for the older package. (Ref: https://www.pycrypto.org/)
Why does it matter?
In addition to the usage of discontinued library that has a lot of vulnerabilities reported in the recent years, usage of PyCrypto makes BeeFish not fully compatible with Python3.
Being specific, I encountered problems using BeeFish in Python3 environment because the PyCrypto package uses Python2 xrange
function several times in its source, which is not available in Python3.
Traceback (most recent call last):
File "/Users/bikalpa/LP/plugins/tools/pak_creator.py", line 5, in <module>
from beefish import encrypt
File "/Users/bikalpa/LP/plugins/env/src/beefish/beefish.py", line 31, in <module>
from Crypto.Cipher import Blowfish
File "/Users/bikalpa/LP/plugins/env/lib/python3.9/site-packages/Crypto/Cipher/Blowfish.py", line 120, in <module>
key_size = xrange(4,56+1)
NameError: name 'xrange' is not defined
Since pycryptodome
provides drop-in replacement to pycrypto
, I suggest the dependency be updated to pycrytpodome
.
>>> beefish.encrypt_file("input.png", "output.png" "p@ssword")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\beefish.py", line 127, in encrypt_file
encrypt(in_fh, out_fh, key, chunk_size, cipher_type)
File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\beefish.py", line 81, in encrypt
cipher = get_cipher(key, iv)
File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\beefish.py", line 53, in get_blowfish_cipher
return Blowfish.new(key, Blowfish.MODE_CBC, iv) File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\Crypto\Cipher\Blowfish.py", line 146, in new
return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\Crypto\Cipher\__init__.py", line 79, in _create_cipher
return modes[mode](factory, **kwargs)
File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\Crypto\Cipher\_mode_cbc.py", line 274, in _create_cbc_cipher
cipher_state = factory._create_base_cipher(kwargs)
File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\Crypto\Cipher\Blowfish.py", line 77, in _create_base_cipher
result = start_operation(c_uint8_ptr(key),
File "C:\Users\megahomyak\AppData\Local\Programs\Python\Python38-32\lib\site-packages\Crypto\Util\_raw_api.py", line 138, in c_uint8_ptr
raise TypeError("Object type %s cannot be passed to C code" % type(data))
TypeError: Object type <class 'str'> cannot be passed to C code
My beefish version is 0.2.1
And every other encryption or decryption method have this problem
Hi I am trying to use beefish with python 3.4 and I get the following error (which I don't get with python 2.7):
File "/Users/cgia/sources/git/backup/backup/utils.py", line 42, in encrypt
encrypt_file(file, '/secrets.enc', 'p@ssword')
File "/Users/cgia/sources/git/backup/env/lib/python3.4/site-packages/beefish.py", line 92, in encrypt_file
encrypt(in_fh, out_fh, key, chunk_size)
File "/Users/cgia/sources/git/backup/env/lib/python3.4/site-packages/beefish.py", line 62, in encrypt
buffer += _gen_padding(bytes_read, cipher.block_size)
File "/Users/cgia/sources/git/backup/env/lib/python3.4/site-packages/beefish.py", line 37, in _gen_padding
return padding + chr(bflag)
TypeError: can't concat bytes to str
I was looking at the source and beefish.py line 37:
return padding + chr(bflag)
The python 3.4 documentation for chr() states:
https://docs.python.org/3.4/library/functions.html#chr
chr(i) - Returns the string representing a character whose Unicode code point is the integer i.
While the documentation for 2.7 states:
https://docs.python.org/2.7/library/functions.html#chr
chr(i) - Return a string of one character whose ASCII code is the integer i.
I attempted to add an str.decode() to line 37, to convert the string to bytes and this seems to work but then I run into other exceptions when trying to decode the file, so I decided I might ask you for help.
to test the differences I used virtualenv with 2.7 and pyvenv with 3.4, with 2.7 the code works perfectly.
thanks
I found this issue while calling beefish.encrypt() in python3.8.
File "/Users/sbs/Library/Python/3.8/lib/python/site-packages/beefish.py", line 75, in encrypt
iv = generate_iv(block_size)
File "/Users/sbs/Library/Python/3.8/lib/python/site-packages/beefish.py", line 45, in generate_iv
return Random.get_random_bytes(block_size)
File "/Users/sbs/Library/Python/3.8/lib/python/site-packages/Crypto/Random/__init__.py", line 41, in get_random_bytes
return _UserFriendlyRNG.get_random_bytes(n)
File "/Users/sbs/Library/Python/3.8/lib/python/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 228, in get_random_bytes
return _get_singleton().read(n)
File "/Users/sbs/Library/Python/3.8/lib/python/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 178, in read
return _UserFriendlyRNG.read(self, bytes)
File "/Users/sbs/Library/Python/3.8/lib/python/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 129, in read
self._ec.collect()
File "/Users/sbs/Library/Python/3.8/lib/python/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 77, in collect
t = time.clock()
AttributeError: module 'time' has no attribute 'clock'
PyCrypto
is calling time.clock() which has been removed.
Also, PyCrypto
seems dead: pycrypto/pycrypto#173. People are suggesting to use PyCryptodome
a fork from PyCrypto
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.