RSA encryption and decryption in Python

In order to make it work you need to convert key from str to tuple before decryption(ast.literal_eval function). Here is fixed code: import Crypto from Crypto.PublicKey import RSA from Crypto import Random import ast random_generator = Random.new().read key = RSA.generate(1024, random_generator) #generate pub and priv key publickey = key.publickey() # pub key export for exchange … Read more

Microsoft Windows Python-3.6 PyCrypto installation error

The file include\pyport.h in Python installation directory does not have #include < stdint.h > anymore. This leaves intmax_t undefined. A workaround for Microsoft VC compiler is to force include stdint.h via OS environment variable CL: Open command prompt Setup VC environment by runing vcvars*.bat (choose file name depending on VC version and architecture) set CL=-FI”Full-Path\stdint.h” … Read more

Pycrypto install fatal error: gmp.h file not found

If you use Homebrew, this should do the trick: brew install gmp env “CFLAGS=-I/usr/local/include -L/usr/local/lib” pip install pycrypto Using env will only make it work for that invocation. If you need to install pycrypto at a later time in this session export the variable instead. export “CFLAGS=-I/usr/local/include -L/usr/local/lib” pip install pycrypto

Encrypt and decrypt using PyCrypto AES-256

Here is my implementation, and it works for me with some fixes. It enhances the alignment of the key and secret phrase with 32 bytes and IV to 16 bytes: import base64 import hashlib from Crypto import Random from Crypto.Cipher import AES class AESCipher(object): def __init__(self, key): self.bs = AES.block_size self.key = hashlib.sha256(key.encode()).digest() def encrypt(self, … Read more

Pip error: Microsoft Visual C++ 14.0 is required

You need to install Microsoft Visual C++ 14.0 to install pycrypto: error: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools”: http://landinghub.visualstudio.com/visual-cpp-build-tools In the comments you ask which link to use. Use the link to Visual C++ 2015 Build Tools. That will install Visual C++ 14.0 without installing Visual Studio. … Read more

How do I install PyCrypto on Windows?

If you don’t already have a C/C++ development environment installed that is compatible with the Visual Studio binaries distributed by Python.org, then you should stick to installing only pure Python packages or packages for which a Windows binary is available. Fortunately, there are PyCrypto binaries available for Windows: http://www.voidspace.org.uk/python/modules.shtml#pycrypto UPDATE: As @Udi suggests in the … Read more