pycrypto

AES decryption fails when decrypting a second time

爱⌒轻易说出口 提交于 2019-12-13 08:14:59
问题 I have this implementation of a reversible encoding: # coding=utf-8 from Crypto.Cipher import AES from Crypto import Random import uuid import unittest import random key = r'Sixteen byte key' # Keep this real secret iv = Random.new().read(AES.block_size) cipher = AES.new(key, AES.MODE_CFB, iv) def encode(role, plaintext): '''Encode the message, prefix with the role specifier''' msg = iv + cipher.encrypt(plaintext) msg = msg.encode('hex') msg = role + '-' + msg return msg def decode(msg): ''

no acceptable C compiler found in $PATH on google compute engine

拥有回忆 提交于 2019-12-13 04:34:54
问题 When I try to install pycrypto on a GCE i get the error "no acceptable C compiler found in $PATH". I use pip like this pip install pycrypto The GCE is a backports-debian-7-wheezy-v20131127 image. I assumed the debian image would have gcc installed, but typing 'gcc' gives 'command not found'. Is there a way to install pycrypto without having to use gcc? Has anyone managed to install pycrypto on GCE yet? 回答1: Try: sudo apt-get install python-crypto I'm glad it worked out 回答2: The default cloud

CryptoJS and Pycrypto working together

十年热恋 提交于 2019-12-13 04:05:03
问题 I'm encrypting a string in a web application using CryptoJS (v 2.3), and I need to decrypt it on the server in Python, so I'm using PyCrypto. I feel like I'm missing something because I can't can it working. Here's the JS: Crypto.AES.encrypt('1234567890123456', '1234567890123456', {mode: new Crypto.mode.CBC(Crypto.pad.ZeroPadding)}) // output: "wRbCMWcWbDTmgXKCjQ3Pd//aRasZ4mQr57DgTfIvRYE=" The python: from Crypto.Cipher import AES import base64 decryptor = AES.new('1234567890123456', AES.MODE

Encrypt using AES-256 like OpenSSL with PyCrypto

依然范特西╮ 提交于 2019-12-12 22:52:05
问题 I'm trying to encrypt a timestamp using AES-256 and Python with base64. The OpenSSL equivalent of the output is generated with this command: openssl enc -aes256 -pass pass:'1Lw2*kx18#AvNuij*iRL1nY1UA_#k8$+' -nosalt -base64 <<< "1489355323" My python code looks like so: import time from base64 import b64encode from Crypto.Cipher import AES key = '1Lw2*kx18#AvNuij*iRL1nY1UA_#k8$+' timestamp = "1489355323" BS = 16 pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) iv = "\x00" * 16

Strange issue with AES CTR mode with Python and Javascript

女生的网名这么多〃 提交于 2019-12-12 18:26:06
问题 I'm trying to decrypt a ciphertext created by CryptoJS using PyCrypto. I am using AES-256-CTR, with a 12-byte random prefix and 4-byte counter. So far, I've had limited success. Please read this previous post where I made a first attempt. This works in Javascript: Install the CryptoCat extension Run CryptoCat Fire up the developer console (F12 in Chrome/Firefox) Run these lines of code key = 'b1df40bc2e4a1d4e31c50574735e1c909aa3c8fda58eca09bf2681ce4d117e11'; msg =

How to encrypt data with RSA private key in python?

耗尽温柔 提交于 2019-12-12 17:55:39
问题 I've installed pyCrypto package on Python 2.7.1 to do some cryptography operations. Q1: The operation that I want to do is encrypting some data with private Key (instead of public Key ). It seems that this library can't do it. Am I right? If so, is there any library capable to do that? Q2: In the documentation it is not mentioned which hash algorithm is used to calculate the signature! How can I find out which hash function is used for sign method? Q3: You see a part of documentation about

PyCrypto Possible To Check If File Already AES Encrypted?

自作多情 提交于 2019-12-12 12:12:00
问题 from Crypto.Cipher import AES def encrypt_file(key, in_filename, out_filename=None, chunksize=64*1024): """ Encrypts a file using AES (CBC mode) with the given key. key: The encryption key - a string that must be either 16, 24 or 32 bytes long. Longer keys are more secure. in_filename: Name of the input file out_filename: If None, '<in_filename>.enc' will be used. chunksize: Sets the size of the chunk which the function uses to read and encrypt the file. Larger chunk sizes can be faster for

encrypt using node.js crypto aes256 and decrypt using python2.7 PyCrypto

我的未来我决定 提交于 2019-12-12 09:52:45
问题 I am trying to encrypt using node.js as follows (node.js v0.10.33): var crypto = require('crypto'); var assert = require('assert'); var algorithm = 'aes256'; // or any other algorithm supported by OpenSSL var key = 'mykey'; var text = 'this-needs-to-be-encrypted'; var cipher = crypto.createCipher(algorithm, key); var encrypted = cipher.update(text, 'utf8', 'hex') + cipher.final('hex'); console.log('encrypted', encrypted, encrypted.length) /* var decipher = crypto.createDecipher(algorithm, key

pycrypto and Google app engine

蓝咒 提交于 2019-12-12 09:48:39
问题 How do you use pycrypto with GAP? It says here that it does not support the latest version. Does that mean that I have to use the version pointed by them ? I tried this but, when I execute setup.py I get the error src/MD2.c:15:20: fatal error: Python.h: No such file or directory compilation terminated. error: command 'gcc' failed with exit status 1 回答1: App Engine 1.7.2, released just a few hours ago, now supports PyCrypto 2.6, the most recent version. The linked doc is likely outdated and

How to store a crypto key securely?

浪尽此生 提交于 2019-12-12 09:35:32
问题 I'm looking at using a crypto lib such as pycrypto for encrypting/decrypting fields in my python webapp db. But encryption algorithms require a key. If I have an unencrypted key in my source it seems silly to attempt encryption of db fields as on my server if someone has access to the db files they will also have access to my python sourcecode. Is there a best-practice method of securing the key used? Or an alternative method of encrypting the db fields (at application not db level)? UPDATE: