pycrypto

AES - Encryption with Crypto (node-js) / decryption with Pycrypto (python)

别说谁变了你拦得住时间么 提交于 2019-11-27 01:07:57
问题 I'm writing this question + answer because I struggled a lot (maybe because of a lack of experience), got lost in many different ways of encrypting/decrypting things with node or python. I thought maybe my case could help people in the future. What I needed to do: Get data from a form, encrypt them using Crypto (node-js) Pass the encrypted data in Python and decrypt it using PyCrypto. I chose to use the AES encryption. Here is how I started (I'm not gonna go through everything I tried): I

Microsoft Windows Python-3.6 PyCrypto installation error

时间秒杀一切 提交于 2019-11-27 00:31:07
pip install pycrypto works fine with python3.5.2 but fails wiht python3.6 with the following error: inttypes.h(26): error C2061: syntax error: identifier 'intmax_t' 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" (use real value for Full-Path for the

PyCrypto problem using AES+CTR

房东的猫 提交于 2019-11-26 23:21:57
问题 I'm writing a piece of code to encrypt a text using symmetric encryption. But it's not coming back with the right result... from Crypto.Cipher import AES import os crypto = AES.new(os.urandom(32), AES.MODE_CTR, counter = lambda : os.urandom(16)) encrypted = crypto.encrypt("aaaaaaaaaaaaaaaa") print crypto.decrypt(encrypted) Here, the decrypted text is different from the original. I don't really understand much about cryptography so please bear with me. I understand the CTR mode requires a

Pip error: Microsoft Visual C++ 14.0 is required

荒凉一梦 提交于 2019-11-26 22:53:03
I just ran the "pip install -U steem"-command and the installation worked well until it failed to install pycrypto. Afterwards I did the "pip install cryptography" command because I thought it was the missing package. So my question is, how I can install steem without the pycrypto-error (or the pycrypto-package in addition) and how to deinstall the cryptography-Package which I don't need. (I'm using Windows 7 and Python 3) Requirement already up-to-date: python-dateutil in c:\users\***\appdata\lo cal\programs\python\python36\lib\site-packages (from dateparser->maya->steem) Collecting regex

How do I use a X509 certificate with PyCrypto?

末鹿安然 提交于 2019-11-26 20:22:21
I want to encrypt some data in python with PyCrypto. However I get an error when using key = RSA.importKey(pubkey) : RSA key format is not supported The key was generated with: openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mycert.key -out mycert.pem The code is: def encrypt(data): pubkey = open('mycert.pem').read() key = RSA.importKey(pubkey) cipher = PKCS1_OAEP.new(key) return cipher.encrypt(data) PyCrypto does not support X.509 certificates. You must first extract the public key with the command: openssl x509 -inform pem -in mycert.pem -pubkey -noout > publickey.pem Then, you

How to read a RSA public key in PEM + PKCS#1 format

不羁岁月 提交于 2019-11-26 19:50:36
问题 I have a RSA public key in PEM format + PKCS#1(I guess): -----BEGIN RSA PUBLIC KEY----- MIGJAoGBAJNrHWRFgWLqgzSmLBq2G89exgi/Jk1NWhbFB9gHc9MLORmP3BOCJS9k onzT/+Dk1hdZf00JGgZeuJGoXK9PX3CIKQKRQRHpi5e1vmOCrmHN5VMOxGO4d+zn JDEbNHODZR4HzsSdpQ9SGMSx7raJJedEIbr0IP6DgnWgiA7R1mUdAgMBAAE= -----END RSA PUBLIC KEY----- I want to get the SHA1 digest of its ASN1 encoded version in Python. The first step should be to read this key, but I failed to do it in PyCrypto: >> from Crypto.PublicKey import RSA >> RSA

Signing and verifying data using pycrypto (RSA)

China☆狼群 提交于 2019-11-26 19:03:26
问题 I am trying to familiarize myself with the pycrypto module, but the lack of clear documentation makes things difficult. To start with, I would like to understand signing and verifying data. Could someone please provide an example for how this would be written? 回答1: This is a fleshed-out version of the example in the documentation: import Crypto.Hash.MD5 as MD5 import Crypto.PublicKey.RSA as RSA import Crypto.PublicKey.DSA as DSA import Crypto.PublicKey.ElGamal as ElGamal import Crypto.Util

How to decrypt password from JavaScript CryptoJS.AES.encrypt(password, passphrase) in Python

我只是一个虾纸丫 提交于 2019-11-26 17:48:15
问题 I have a password which is encrypt from JavaScript via var password = 'sample' var passphrase ='sample_passphrase' CryptoJS.AES.encrypt(password, passphrase) Then I tried to decrypt the password comes from JavaScript in Python: from Crypto.Cipher import AES import base64 PADDING = '\0' pad_it = lambda s: s+(16 - len(s)%16)*PADDING key = 'sample_passphrase' iv='11.0.0.101' #------> here is my question, how can I get this iv to restore password, what should I put here? key=pad_it(key) #------>

RSA encryption and decryption in Python

≡放荡痞女 提交于 2019-11-26 17:37:26
问题 I need help using RSA encryption and decryption in Python. I am creating a private/public key pair, encrypting a message with keys and writing message to a file. Then I am reading ciphertext from file and decrypting text using key. I am having trouble with the decryption portion. As you can see in my code below, when I put in decrypted = key.decrypt(message) that the program works, yet the decrypted message is encrypted again. It seems like it is not reading the ciphertext from the file. Can

Pip error: Microsoft Visual C++ 14.0 is required

点点圈 提交于 2019-11-26 17:28:44
问题 I just ran the "pip install -U steem"-command and the installation worked well until it failed to install pycrypto. Afterwards I did the "pip install cryptography" command because I thought it was the missing package. So my question is, how I can install steem without the pycrypto-error (or the pycrypto-package in addition) and how to deinstall the cryptography-Package which I don't need. (I'm using Windows 7 and Python 3) Requirement already up-to-date: python-dateutil in c:\users\***