pycrypto

Using pycrypto, how to import a RSA public key and use it to encrypt a string?

有些话、适合烂在心里 提交于 2019-12-02 21:06:37
The RSA public key: pubkey = 'MIGfMA0GCSqGSIb3DQEBA3UAA4GNADCBiQKBgQC35eMaYoJXEoJt5HxarHkzDBEMU3qIWE0HSQ77CwP/8UbX07W2XKwngUyY4k6Hl2M/n9TOZMZsiBzer/fqV+QNPN1m9M94eUm2gQgwkoRj5battRCaNJK/23GGpCsTQatJN8PZBhJBb2Vlsvw5lFrSdMT1R7vaz+2EeNR/FitFXwIDAQAB' how to import it and use it to encrypt a string? I tried the following code but RSA.construct() raises exception (TypeError: must be long, not str). from Crypto.PublicKey import RSA from Crypto.Util import asn1 from base64 import b64decode keyDER = b64decode(pubkey) seq = asn1.DerSequence() seq.decode(keyDER) keyPub = RSA.construct((seq[0], seq[1]))

How do I create a user and set a password using ansible?

*爱你&永不变心* 提交于 2019-12-02 20:32:49
The documentation refers us to the github example , but this is a bit sparse and mysterious. It says this: # created with: # crypt.crypt('This is my Password', '$1$SomeSalt') password: $1$SomeSalt$UqddPX3r4kH3UL5jq5/ZI. but crypt.crypt doesn't emit what the example shows. It also uses MD5. I tried this: # python import crypt crypt.crypt('This is my Password', '$6$somereallyniceandbigrandomsalt$') >> '$69LxCegsnIwI' but the password field of user should get something like this: password: $6$somereallyniceandbigrandomsalt$UqddPX3r4kH3UL5jq5/ZI. which includes three $ delimiters separating the 6

Pycrypto install fatal error: gmp.h file not found

余生颓废 提交于 2019-12-02 17:27:48
It seems like there are a number of people who have had a similar problem, however, after much searching I haven't been able to find a solution that works with my particular architecture. I'm trying to install Pycrypto (as a subsidiary of Fabric) to no avail. I'm running Mac 10.8.2, python 2.7.3 via Homebrew, and XCode 4.6 -- installing with pip or easy_install (I've tried both). From what I can tell, the problem could either be with respect to my version of XCode or because of my libraries. The Command Line Tools for XCode have been installed and I have tried placing setenv ARCHFLAGS "-arch

AES decryption padding with PKCS5 Python

淺唱寂寞╮ 提交于 2019-12-02 16:00:41
I have been trying to implement AES CBC decryption in Python. Since the ciphered text is not a multiple of 16bytes, padding was necessary. Without padding, this error surfaced "TypeError: Odd-length string" But I could not find a proper reference for implementing PKCS5 in PyCrypto Python. Are there any commands to implement this? Thanks After looking into Marcus's suggestion I did this. My goal actually is to decrypt a hex message(128bytes) using this code. However, the output is " ?:" which is very small and the unpad command is deleting those bytes. This is the code. from Crypto.Cipher

PyCrypto not fully installed on Windows XP

℡╲_俬逩灬. 提交于 2019-12-02 15:50:27
I ran python setup.py install in a Windows XP console, and it reported as follows: running install running build running build_py running build_ext warning: GMP library not found; Not building Crypto.PublicKey._fastmath. building 'Crypto.Random.OSRNG.winrandom' extension error: None When I try to run a script with import Crypto.Cipher.AES , it doesn't work, saying: ImportError: cannot import name AES How can I fix this? John Paulett On windows, it may just be easier installing PyCrypto via a prebuilt windows installer. The Voidspace site has PyCrypto 2.1 and 2.3 installers for Python 2.2-2.7 .

Pass list to AES key generator in PyCrypto

回眸只為那壹抹淺笑 提交于 2019-12-02 08:08:11
I'm attempting to generate an AES key with Pycrypto but receive the following error: TypeError: 'list' does not support the buffer interface for the following statement: aescipher = AES.new(mykey, AES.MODE_ECB) mykey , is of type list and contains [1885434739, 825373440, 0, 0] Does anyone know how I can convert mykey into the correct type for the AES.new function? You should not supply any kind of list/array when creating an AES key. The raw key bytes are normally supplied using a byte array of keysize / 8 bytes. For AES, the only key sizes that are supported are 128, 192 and 256 bits or 16,

How come I can't decrypted my AES encrypted message on someone elses AES decryptor?

淺唱寂寞╮ 提交于 2019-12-02 07:48:28
from Crypto.Cipher import AES import os key = 'mysecretpassword' iv = os.urandom(16) plaintext1 = 'Secret Message A' encobj = AES.new(key, AES.MODE_CBC, iv) ciphertext1 = encobj.encrypt(plaintext1) encryptedText = ciphertext1.encode('base64') print encryptedText decobj = AES.new(key, AES.MODE_CBC, iv) print decobj.decrypt(ciphertext1) I copied the printed value of encryptedText and the key from my code and pasted to the websites below. http://www.everpassword.com/aes-encryptor http://www.nakov.com/blog/2011/12/26/online-aes-encryptor-decryptor-javascript/ I would expected it to be able to

RSA communication between Javascript and Python

南笙酒味 提交于 2019-12-02 05:01:44
问题 I am working on a prototype, so it needs to use RSA between a Chrome Extension and a Python Server. So far I was planning on using https://sourceforge.net/projects/pidcrypt/ and https://www.dlitz.net/. However, while I can get decrypt and encrypt to work as per the documentation, I cannot get one to decrypt each other's message. Can someone please, either suggest libraries that interoperate or let me know if I am doing something wrong with this libraries? From what I worked out, pidder uses

RSA communication between Javascript and Python

被刻印的时光 ゝ 提交于 2019-12-01 23:18:47
I am working on a prototype, so it needs to use RSA between a Chrome Extension and a Python Server. So far I was planning on using https://sourceforge.net/projects/pidcrypt/ and https://www.dlitz.net/ . However, while I can get decrypt and encrypt to work as per the documentation, I cannot get one to decrypt each other's message. Can someone please, either suggest libraries that interoperate or let me know if I am doing something wrong with this libraries? From what I worked out, pidder uses RSA PKCS#1 encryption-style padding (type 2). From googling, I sort of worked out that it is the type

app engine: ImportError: No module named Crypto.Hash

时光总嘲笑我的痴心妄想 提交于 2019-12-01 15:52:09
I have a script that uses Crypto.Hash but import fails with error: ImportError: No module named Crypto.Hash in my sys.path if I print the sys.path list, there is this entry (among others): /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/pycrypto-2.6 If I open the path above, there is no pycrypto-2.6 directory. How can I get to load pycrypto 2.6? If I import Crypto.Hash running python from command line it works I have to point out that pycrypto is supported by App Engine, it is included in this list .