pycrypto

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

人走茶凉 提交于 2019-11-27 19:42:46
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.importKey(my_key) ValueError: RSA key format is not supported The documentation of PyCrypto says PEM +

RSA encryption and decryption in Python

北战南征 提交于 2019-11-27 18:48:40
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 anyone help me write this code so decryption reads ciphertext from file and then uses key to decrypt

Signing and verifying data using pycrypto (RSA)

烈酒焚心 提交于 2019-11-27 17:32:31
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? 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.number as CUN import os plaintext = 'The rain in Spain falls mainly on the Plain' # Here is a hash of the

PyCrypto Errors with .p12 file from Google Developer Console

时间秒杀一切 提交于 2019-11-27 16:59:23
问题 I am trying to implement Google Identity Toolkit (gitkitv3) in GAE Python. After a user signs in on the website, I get the following errors: 'PKCS12 format is not supported by the PyCrpto library. ' NotImplementedError: PKCS12 format is not supported by the PyCrpto library. Try converting to a "PEM" (openssl pkcs12 -in xxxxx.p12 -nodes -nocerts > privatekey.pem) or using PyOpenSSL if native code is an option. Based on a SO reply, I ran the following commands on my x.p12 file and used the

from Crypto import Random -> ImportError: cannot import name Random

社会主义新天地 提交于 2019-11-27 16:07:55
问题 I have installed pycrypto (version 2.3) to /usr/local/lib/python2.6/dist-packages/Crypto/ and I am able to see the Random package there. But when I try to import the Crypto.Random, it pomps me that from Crypto.Random import * ImportError: No module named Random Does anyone know why this would even happen? Thanks. import Crypto import os print(Crypto.__file__); print (dir(Crypto)); print(os.listdir(os.path.dirname(Crypto.__file__))) Results: /usr/lib/python2.6/dist-packages/Crypto/__init__.pyc

Broken Pipe error when using pip to install pycrypto on Mac OS X

核能气质少年 提交于 2019-11-27 11:41:27
I am attempting to install pycrypto (version 2.3) on OS X via pip. I am getting a "Broken pipe" error when the compiler attempts to compile MD2.c. I get a very similar error when using easy_install. Here is the error that I am getting: bash-3.2$ bash-3.2$ sudo pip install pycrypto Password: Downloading/unpacking pycrypto Running setup.py egg_info for package pycrypto Installing collected packages: pycrypto Running setup.py install for pycrypto warning: GMP library not found; Not building Crypto.PublicKey._fastmath. building 'Crypto.Hash.MD2' extension gcc-4.2 -fno-strict-aliasing -fno-common

On Mac OS X, easy_install fabric and/or easy_install pycrypto fails due to linker error “illegal text-relocation”

邮差的信 提交于 2019-11-27 08:12:00
问题 When trying to easy_install fabric (or easy_install pycrypto, which fabric depends on), I got the following linker error on Mac OS X: ld: illegal text-relocation to ___gmp_binvert_limb_table in /usr/local/lib/libgmp.a(mp_minv_tab.o) from ___gmpn_divexact_1 in /usr/local/lib/libgmp.a(dive_1.o) for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) error: Setup script exited with error: command 'clang' failed with exit status 1 回答1: I was using a

Python Encrypting with PyCrypto AES

好久不见. 提交于 2019-11-27 07:28:54
I just found pycrypto today, and I've been working on my AES encryption class. Unfortunately it only half-works. self.h.md5 outputs md5 hash in hex format, and is 32byte. This is the output. It seems to decrypt the message, but it puts random characters after decryption, in this case \n\n\n... I think I have a problem with block size of self.data, anyone know how to fix this? Jans-MacBook-Pro:test2 jan$ ../../bin/python3 data.py b'RLfGmn5jf5WTJphnmW0hXG7IaIYcCRpjaTTqwXR6yiJCUytnDib+GQYlFORm+jIctest 1 2 3 4 5 endtest\n\n\n\n\n\n\n\n\n\n' from Crypto.Cipher import AES from base64 import

PyCrypto on python 3.5

血红的双手。 提交于 2019-11-27 05:17:09
问题 I found some PyCrypto installers for Python 3.3 and 3.4, but nothing for Python 3.5. When I try to install PyCrypton using pip install , it says: warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath. Is there any way to install PyCrypto on Python 3.5 in Windows 10? Thanks! 回答1: That warning shouldn't stop the build, more likely you are lacking the Visual Studio 2015 compiler which is necessary to build binary extensions (which PyCrypto has). See the Python Packaging

Saving RSA keys to a file, using pycrypto

回眸只為那壹抹淺笑 提交于 2019-11-27 03:21:35
问题 I’m using PyCrypto 2.3 and I would like to save the keys I have generated into a file, so as to distribute them to the client and server. I can’t seem to find a way to print the keys correctly, neither can I find examples on the internet. def resetKeys(self): keys = RSA.generate(1024) privHandle = open(self.privateKeyFile, 'wb') privHandle.write(keys.privatekey()) privHandle.close() pubHandle = open(self.publicKeyFile, 'wb') pubHandle.write(keys.publickey()) pubHandle.close() This codes does