Comments (8)
Sorry, my fault, copy aes256.py
in the same folder with your testing.py
and use this code
from aes256 import aes256
# encryption
encrypted = aes256().encrypt('TEXT', 'PASSWORD')
print(encrypted)
# decryption
print(aes256().decrypt(encrypted, 'PASSWORD'))
from aes-everywhere.
The same error still happening, even after using the above code
Traceback (most recent call last):
File "<mydirectory>/Python Testing/testing.py", line 4, in <module>
encrypted = aes256().encrypt('TEXT', 'PASSWORD')
File "<mydirectory>\Python Testing\aes256.py", line 39, in encrypt
return base64.b64encode(b'Salted__' + salt + cipher.encrypt(self.__pkcs5_padding(raw)))
File "C:\Users\<myname>\AppData\Local\Programs\Python\Python36\lib\site-packages\Crypto\Cipher\_mode_cbc.py", line 160, in encrypt
expect_byte_string(plaintext)
File "C:\Users\<myname>\AppData\Local\Programs\Python\Python36\lib\site-packages\Crypto\Util\_raw_api.py", line 172, in expect_byte_string
raise TypeError("Only byte strings can be passed to C code")
TypeError: Only byte strings can be passed to C code
A little bit reading on _mode_cbc.py, it looks it requires byte string, but it's getting string returned from pkcs5_padding(raw).
UPDATE:
I add the following lines of code at __pkcs5_padding() for 'aes256.py' to replace the return statement as below:
s = s + (self.BLOCK_SIZE - len(s) % self.BLOCK_SIZE) * chr(self.BLOCK_SIZE - len(s) % self.BLOCK_SIZE)
b = bytes(s, 'utf-8')
return b
and it works.
By following the sample code, it should return the statement as below
b'U2FsdGVkX18DbtQ7JRk3E+QZnxckBINY9cZVaMZ3Ghk='
b'TEXT'
Attached is the modified aes256.py and testing.py for your testing.
aes256 testing.zip
from aes-everywhere.
from aes256 import aes256
# encryption
encrypted = aes256().encrypt('TEXT', b'PASSWORD')
print(encrypted)
# decryption
print(aes256().decrypt(encrypted, b'PASSWORD'))
from aes-everywhere.
Also try to add encoding in your testing.py
at the beginning of the file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from aes-everywhere.
Using the given sample code, this error pops out
Traceback (most recent call last):
File "d:/Google Drive/UM/UM Sem 7/#IPPI/#Sem 7/Coding and Testing/Python Testing/testing.py", line 7, in <module>
encrypted = aes256().encrypt('TEXT', b'PASSWORD')
File "d:\Google Drive\UM\UM Sem 7\#IPPI\#Sem 7\Coding and Testing\Python Testing\aes256.py", line 37, in encrypt
key, iv = self.__derive_key_and_iv(passphrase, salt)
File "d:\Google Drive\UM\UM Sem 7\#IPPI\#Sem 7\Coding and Testing\Python Testing\aes256.py", line 93, in __derive_key_and_iv
d_i = md5(d_i + password.encode('utf-8') + salt).digest()
AttributeError: 'bytes' object has no attribute 'encode'
So, if I changed
d_i = md5(d_i + password.encode('utf-8') + salt).digest()
to
d_i = md5(d_i + password + salt).digest()
now this error happens:
Traceback (most recent call last):
File "<mydirectory>/Python Testing/testing.py", line 7, in <module>
encrypted = aes256().encrypt('TEXT', b'PASSWORD')
File "<mydirectory>\Python Testing\aes256.py", line 39, in encrypt
return base64.b64encode(b'Salted__' + salt + cipher.encrypt(self.__pkcs5_padding(raw)))
File "C:\Users\<myname>\AppData\Local\Programs\Python\Python36\lib\site-packages\Crypto\Cipher\_mode_cbc.py", line 160, in encrypt
expect_byte_string(plaintext)
File "C:\Users\<myname>\AppData\Local\Programs\Python\Python36\lib\site-packages\Crypto\Util\_raw_api.py", line 172, in expect_byte_string
raise TypeError("Only byte strings can be passed to C code")
TypeError: Only byte strings can be passed to C code
from aes-everywhere.
Okey, I updated aes256.py
, try it now
from aes-everywhere.
It works.
b'U2FsdGVkX18RTb+muaFK+NXQuNpZa6EFDCOVT6vd4ng='
b'TEXT'
and second attempt produced this:
b'U2FsdGVkX1/eGk5cX+Bh0ZIezVVZXQgui3S+txk2Z1k='
b'TEXT'
These are correct right? New encrypted value for each attempt even though the plaintext is the same?
from aes-everywhere.
Yes, it's correct, it uses random salt for security reason
from aes-everywhere.
Related Issues (20)
- Unable to install with composer HOT 2
- Language Request HOT 1
- Add binary data support HOT 3
- No sys/time.h on Windows HOT 3
- Support For Dart HOT 4
- Memory corruption with cpp on ubuntu 16.04 x64 HOT 1
- AttributeError: module 'time' has no attribute 'clock' HOT 2
- Different result in c++ and php HOT 3
- Add openssl shell script HOT 1
- SecureRandom.generateSeed block threads when large concurrency HOT 1
- lua install error HOT 5
- ModuleNotFoundError: No module named 'Crypto' HOT 2
- C++
- c++ AES runtime error HOT 1
- Support For Rust HOT 2
- how to run javascript version in the browser? HOT 2
- Different decryption results with python and Java/Kotlin. HOT 1
- .NET C# "Padding is invalid and cannot be removed." HOT 5
- Cryptography problems HOT 1
- Security warnings for the node and possibly other packages HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aes-everywhere.