pycrypto

python 实现 AES CBC模式加解密

生来就可爱ヽ(ⅴ<●) 提交于 2020-04-24 23:25:07
AES加密方式有五种:ECB, CBC, CTR, CFB, OFB 从安全性角度推荐CBC加密方法,本文介绍了CBC,ECB两种加密方法的python实现 python 在 Windows 下使用AES时要安装的是pycryptodome 模块 pip install pycryptodome python 在 Linux 下使用AES时要安装的是pycrypto模块 pip install pycrypto CBC加密需要一个十六位的key(密钥)和一个十六位iv(偏移量) 1. 加密 加密时,明文首先与IV异或,然后将结果进行块加密,得到的输出就是密文,同时本次的输出密文作为下一个块加密的IV。 2. 解密 解密时,先将密文的第一个块进行块解密,然后将结果与IV异或,就能得到明文,同时,本次解密的输入密文作为下一个块解密的IV。 3. 代码:    # -*- coding=utf-8-*- from Crypto.Cipher import AES import os from Crypto import Random import base64 """ aes加密算法 padding : PKCS7 """ class AESUtil: __BLOCK_SIZE_16 = BLOCK_SIZE_16 = AES.block_size @staticmethod def

使用Cygwin和 mingw 安装 python paramiko模块

我怕爱的太早我们不能终老 提交于 2020-03-11 22:24:49
1. 所需软件包 python http://www.python.org/ftp/python/ paramiko http://www.lag.net/paramiko/download/paramiko-1.7.7.1.zip Cygwin http://cygwin.com/setup.exe pycrypto http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.tar.gz mingw http://sourceforge.net/projects/mingw/ 2. 安装 python (忽略) 3. 安装mingw ,如果本地没有gcc 则需要安装这个。下载后的exe文件进行网络安装,假设目录为C:\mingw,在PATH中加入 C:\mingw\bin,并在c:\python24\lib\distutils下新建一个名称是distutils.cfg的文件,填入: [build] compiler=mingw32 4. 安装Cygwin 下载后的exe文件进行网络安装 http://www.cygwin.cn/site/install/ ,这里我们需要选择deve包里的 binutils 其他的可以不选 5. 安装PyCrypto 解压缩 在dos下进入解压缩的目录,运行 python setup

PyCryptodome Error: MAC Check Failed

大憨熊 提交于 2020-01-25 06:41:07
问题 I am working on an encryption program with Pycryptodome in Python 3. I am trying to encrypt a (byte) string and then decrypt it and verify the MAC tag. When I get to verify it, an error is thrown. This is the code: from Crypto.Cipher import AES from Crypto.Random import get_random_bytes aes_key = get_random_bytes(24) aes_cipher = AES.new(aes_key, AES.MODE_GCM) encrypted, MACtag = aes_cipher.encrypt_and_digest(b"A random thirty two byte string.") # Imagine this is happening somewhere else new

PyCryptodome Error: MAC Check Failed

丶灬走出姿态 提交于 2020-01-25 06:40:46
问题 I am working on an encryption program with Pycryptodome in Python 3. I am trying to encrypt a (byte) string and then decrypt it and verify the MAC tag. When I get to verify it, an error is thrown. This is the code: from Crypto.Cipher import AES from Crypto.Random import get_random_bytes aes_key = get_random_bytes(24) aes_cipher = AES.new(aes_key, AES.MODE_GCM) encrypted, MACtag = aes_cipher.encrypt_and_digest(b"A random thirty two byte string.") # Imagine this is happening somewhere else new

AttributeError: module 'time' has no attribute 'clock' in Python 3.8

ぃ、小莉子 提交于 2020-01-22 18:23:29
问题 I have written code to generate public and private keys. It works great at Python 3.7 but it fails in Python 3.8. I don't know how it fails in the latest version. Help me with some solutions. Here's the Code: from Crypto.PublicKey import RSA def generate_keys(): modulus_length = 1024 key = RSA.generate(modulus_length) pub_key = key.publickey() private_key = key.exportKey() public_key = pub_key.exportKey() return private_key, public_key a = generate_keys() print(a) Error in Python 3.8 version:

Pass list to AES key generator in PyCrypto

纵饮孤独 提交于 2020-01-22 03:20: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? 回答1: You should not supply any kind of list/array when creating an AES key. The raw key bytes are normally supplied using a byte

C# RFC2898DeriveBytes is working but Python PBKDF2 generated key and IV are not working with Python AES Decryption

≯℡__Kan透↙ 提交于 2020-01-14 03:13:51
问题 I have a problem in hand to decrypt the AES encrypted cipher-text which specifications are following The cipher-text consists of: · 256 bytes of RFC2898-derived salt, followed by a message that was AES-encrypted using password, 'password' and derived IV. Sample Message is "This is my secret string, lorem ipsum" and password is "password" which is encrypted using C# code This message is decrypting fine with following c# code private static readonly int SALT_SIZE = 256; public static void

Install paramiko on Windows

大憨熊 提交于 2020-01-09 18:05:00
问题 OK. I read installing paramiko on Windows. All mentioned methods simply do not work. Authors have different environments with different components/libraries installed. Or may be they don't test their solutions before posting an answer :) I removed all python versions and libs from my machine (Windows 8 x64) and tried to install python and paramiko from scratch. Method number 1 (FAILED) Install python-2.7.3.amd64.msi Install pycrypto-2.6.win-amd64-py2.7.exe Download https://github.com/paramiko

Install paramiko on Windows

风流意气都作罢 提交于 2020-01-09 18:02:54
问题 OK. I read installing paramiko on Windows. All mentioned methods simply do not work. Authors have different environments with different components/libraries installed. Or may be they don't test their solutions before posting an answer :) I removed all python versions and libs from my machine (Windows 8 x64) and tried to install python and paramiko from scratch. Method number 1 (FAILED) Install python-2.7.3.amd64.msi Install pycrypto-2.6.win-amd64-py2.7.exe Download https://github.com/paramiko

Install paramiko on Windows

六月ゝ 毕业季﹏ 提交于 2020-01-09 18:00:29
问题 OK. I read installing paramiko on Windows. All mentioned methods simply do not work. Authors have different environments with different components/libraries installed. Or may be they don't test their solutions before posting an answer :) I removed all python versions and libs from my machine (Windows 8 x64) and tried to install python and paramiko from scratch. Method number 1 (FAILED) Install python-2.7.3.amd64.msi Install pycrypto-2.6.win-amd64-py2.7.exe Download https://github.com/paramiko