pycrypto

HMAC-SHA256 with AES-256 in CBC mode

断了今生、忘了曾经 提交于 2019-12-11 03:33:09
问题 I recently came across the following code sample for encrypting a file with AES-256 CBC with a SHA-256 HMAC for authentication and validation: aes_key, hmac_key = self.keys # create a PKCS#7 pad to get us to `len(data) % 16 == 0` pad_length = 16 - len(data) % 16 data = data + (pad_length * chr(pad_length)) # get IV iv = os.urandom(16) # create cipher cipher = AES.new(aes_key, AES.MODE_CBC, iv) data = iv + cipher.encrypt(data) sig = hmac.new(hmac_key, data, hashlib.sha256).digest() # return

Python: open with .Cer file to get public key and then perform verification

徘徊边缘 提交于 2019-12-11 02:52:28
问题 I have a .cer file containing public key. I need to use this file to verify signature signed by corresponding private key. I have the signature and public key. I need to verify the signature. I'm getting result as false. Below is the code: def verify_sign(public_key_loc, signature, data): ''' Verifies with a public key from whom the data came that it was indeed signed by their private key param: public_key_loc Path to public key param: signature String signature to be verified return: Boolean

Problems with AES in crypto-js and pycrypto

血红的双手。 提交于 2019-12-10 21:07:42
问题 I try to implement a communication between crypto-js (a javascript crypto library) and pycrypto (a python crypto library) On the python server side I encrypt a string with an iv and a passphrase and send the iv with the encrypted text base64 encoded to the javascript client side . Then I want to decrypt the string with the passphrase the user can enter. python - server from Crypto.Cipher import AES from Crypto import Random iv = Random.get_random_bytes(16) key = "1234567812345678" aes = AES

PyCrypto: Decrypt only with public key in file (no private+public key)

好久不见. 提交于 2019-12-10 20:26:20
问题 Hello everyone. I am trying to play a bit with RSA public and private keys and encryption/decryption with PyCrypto and I have encountered and issue that seems kind of strange to me (it probably makes a lot of sense the way it's working now, but I don't know much about RSA asymmetric encryption and that's why it's puzzling me). It is the inability I have encountered to decrypt something having only the public key. Here's the thing: I have a server and a client. I want the server to "recognize"

Making RSA encryption compatible in Python (PyCrypto) and PHP (OpenSSL)

社会主义新天地 提交于 2019-12-10 18:08:02
问题 I am migrating an entire PHP API, and while I used PyCrypto before, I am not sure how to translate the following encryption call, since I need the exact same result. The PHP call is: define('KEY', "-----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC81t5iu5C0JxYq5/XNPiD5ol3Z w8rw3LtFIUm7y3m8o8wv5qVnzGh6XwQ8LWypdkbBDKWZZrAUd3lybZOP7/82Nb1/ noYj8ixVRdbnYtbsSAbu9PxjB7a/7LCGKsugLkou74PJDadQweM88kzQOx/kzAyV bS9gCCVUguHcq2vRRQIDAQAB -----END PUBLIC KEY-----"); $cypher = ""; $result =

How can I install pycrypto on a 64-bit Windows 7 machine?

↘锁芯ラ 提交于 2019-12-10 17:10:32
问题 I tried installing PyCrypto using pip , but it complained about needing vcvarsall.bat. I installed Visual Studio 2008, but now I get ValueError: [u'path'] when I try to install it from pip . I tried downloading a pre-built binary from Voidspace, but they only have 32-bit versions, and it doesn't seem to install correctly on my machine (it says it succeeded, but running python and trying import Crypto gives me an ImportError: No module named Crypto ). What do I need to do? 回答1: Voidspace now

ImportError: No module named 'Crypto'

℡╲_俬逩灬. 提交于 2019-12-10 14:11:18
问题 I am working with pycrypto. It works fine on my local windows machine, but when I move it to my python box I get an error with importing the module: from Crypto.Cipher import ARC4 ImportError: No module named 'Crypto' The output of python3.3 -c "from Crypto.Cipher import ARC4" Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named 'Crypto' output of pip3 list has a reference includes pycrypto (2.6.1) I know it works with Python 2.7.6, but I wrote

How to add a padding to the data to make it acceptable for AES256 encryption algorithm in pycrypto library

旧时模样 提交于 2019-12-10 13:13:46
问题 Can someone tell me how to add a padding to the data to make it acceptable for AES256 encryption algorithm in pycrypto library (Python). Thanks a lot in advance.. :) 回答1: Looking at the documentation, it seems that it's up to you, the library user, to pad the data yourself. The documentation states that the block size for AES is always 16 bytes, so you need to pad the data to a multiple of 16 bytes. How the padding is done depends on the type of the data. For strings the best approach is

Encrypt with Node.js AES CTR and decrypt with PyCrypto

末鹿安然 提交于 2019-12-10 11:46:30
问题 Okay, so basically I am having issues decrypting with Python. I've managed to encrypt/decrypt data with Node.js - using "aes-128-ctr", the same goes for PyCrypto, but when I try to encrypt with Node.js and decrypt with Python I get invalid deciphered text. Node.js code: var key = "1234567890123456"; var cipher = crypto.createCipher("aes-128-ctr",key) var ctext = cipher.update('asasasa','utf8','hex') + cipher.final('hex') console.log(ctext) // outputs: "f2cf6ecd8f" Python code: counter =

PyCrypto install by copying 'lib' folder on Windows7 64bit

六眼飞鱼酱① 提交于 2019-12-10 11:43:31
问题 I'm trying to install PyCrypto 2.4.1 on my local machine (Windows 7 64bit). But, I got following messages on 'python setup.py install'. running install running build running build_py running build_ext warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath. building 'Crypto.Random.OSRNG.winrandom' extension error: Unable to find vcvarsall.bat What I want to ask is this: can I just copy lib folder which contains Crypto folder in it to where my app is located? I'm