pycryptodome

CryptoJS decode with PyCrypto

懵懂的女人 提交于 2021-01-29 05:23:41
问题 Hey I have such Javascript code CryptoJS.algo.AES.keySize = 32, CryptoJS.algo.EvpKDF.cfg.iterations = 1e4, CryptoJS.algo.EvpKDF.cfg.keySize = 32; var decrypted = CryptoJS.AES.decrypt(message, passphrase); And I need to create an analog using Python (I'm trying to use pycryptodome) But I have several questions: Have can I get key and iv from passphrase? How should reflect all these (CryptoJS.algo.AES.keySize = 32, CryptoJS.algo.EvpKDF.cfg.iterations = 1e4, CryptoJS.algo.EvpKDF.cfg.keySize = 32

Pycrypto AES GCM encryption and Java decryption

删除回忆录丶 提交于 2021-01-27 20:39:04
问题 I'm using Pycryptodome (a PyCrypto fork) to create AES-GCM ciphertexts. I use the following Python code to encrypt: cek = os.urandom(16) nonce = os.urandom(12) cipher = AES.new(cek, AES.MODE_GCM, nonce=nonce, mac_len=16) ciphertext = cipher.encrypt(message) I then pass this to Java to decrypt: byte[] nonce = new byte[12]; Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding"); GCMParameterSpec gcmSpec = new GCMParameterSpec(128, iv); SecretKeySpec secretKeySpec = new SecretKeySpec(cek, "AES"

Encrypt a big file that does not fit in RAM with AES-GCM

冷暖自知 提交于 2020-12-14 06:30:31
问题 This code works for a file myfile which fits in RAM: import Crypto.Random, Crypto.Cipher.AES # pip install pycryptodome nonce = Crypto.Random.new().read(16) key = Crypto.Random.new().read(16) # in reality, use a key derivation function, etc. ouf of topic here cipher = Crypto.Cipher.AES.new(key, Crypto.Cipher.AES.MODE_GCM, nonce=nonce) out = io.BytesIO() with open('myfile', 'rb') as g: s = g.read() ciphertext, tag = cipher.encrypt_and_digest(s) out.write(nonce) out.write(ciphertext) out.write

RSA decryption of AES Session key fails with 'AttributeError: 'bytes' object has no attribute 'n'

[亡魂溺海] 提交于 2020-12-01 11:07:37
问题 I'm working on implementing a public key encryption from PyCryptodome on Python 3.6. When I try to create a symmetric encryption key and encrypt/decrypt variables, it all works fine. But the minute I introduce RSA (and PKCS1_OAEP), it all goes down the tubes - the session_key encrypts fine but when I try and decrypt it, I get the following error: Traceback (most recent call last): File "enctest.py", line 109, in <module> deckey = decrypt_val(enckey) File "enctest.py", line 77, in decrypt_val

python的加密方式

北城余情 提交于 2020-11-24 03:26:42
MD5加密 这是一种使用非常广泛的加密方式,不可逆的,在日常字符串加密中经常会用到,下面我简单介绍一下这种方式,主要用到Python自带的模块hashlib,测试代码如下,先创建一个md5对象,然后直接加密就行: import hashlib def MD5(string): '''md5加密''' h1 = hashlib.md5() # 创建md5对象 # 声明encode h1.update(string.encode(encoding = 'utf-8')) return h1.hexdigest() if __name__ == "__main__": string = "MD5加密" print('MD5加密前为:' + string) print('MD5加密后为:' + MD5(string)) 运行结果: MD5加密前为:MD5加密 MD5加密后为:e5c7bda34849527574a025bc06867c11 哈希加密 这里以SHA1(安全哈希)为例,简单介绍一下Python是如何进行哈希加密的,也用到hashlib这个模块,测试代码如下,非常简单,先创建sha1对象,然后直接加密就行,这里也支持 SHA224,SHA256等加密方式: import hashlib def hash(string): '''哈希加密''' h1 = hashlib.sha1(

Pip:

陌路散爱 提交于 2020-11-15 04:02:51
Crypto 库异常 from Crypto.Cipher import AES File "/root/www/Mkilometers/app/env/lib/python3.7/site-packages/Crypto/Cipher/__init__.py", line 27, in <module> from Crypto.Cipher._mode_ecb import _create_ecb_cipher File "/root/www/Mkilometers/app/env/lib/python3.7/site-packages/Crypto/Cipher/_mode_ecb.py", line 29, in <module> from Crypto.Util._raw_api import (load_pycryptodome_raw_lib, File "/root/www/Mkilometers/app/env/lib/python3.7/site-packages/Crypto/Util/_raw_api.py", line 33, in <module> from Crypto.Util.py3compat import byte_string ImportError: cannot import name 'byte_string' from 'Crypto

20183215 实验三《Python程序设计》实验报告

╄→гoц情女王★ 提交于 2020-08-16 14:24:04
20183215 2019-2020-2 《Python程序设计》实验三报告 课程:《Python程序设计》 班级: 1832 姓名: 董振龙 学号: 20183215 实验教师:王志强 实验日期:2020年5月16日 必修/选修:公选课 1.实验内容 1.创建服务端和客户端,选择一个通信端口,用Python语言编程实现通信演示程序; 2.要求包含文件的基本操作,例如打开和读写操作。 3.要求发送方从文件读取内容,加密后并传输;接收方收到密文并解密,保存在文件中。 4.程序代码托管到码云。 2. 实验过程及结果 实验开始之前,我设想了一下实验结束后的效果,总觉得光秃秃的控制台缺乏美感(尽管是pycharm),于是,我打算加入GUI图形界面,既然追求美感,就贯彻到底咯。 首先,我打开了一个软件: wxFormBuilder (这里我参考了一个 大佬的博客 ),打开后的界面是这样的: 我们先选择Forms点击Frame,然后再建立几个boxsizer,加入一些必备控件textctrl、button,如图,其中,设置bsizer5的proportion为9,使其看上去更加和谐 最后进行一些细节上的设置,例如按钮名称以及事件绑定。最终效果如图: 其中三个按钮分别绑定事件: 保存之后可以导出对应的 .py文件 ,基本重复上述操作,可以得到客户端的图形界面和对应的 .py文件

【Share & Backup】FreeCrawl

房东的猫 提交于 2020-07-29 02:53:55
分享个一份临时写的代码,感兴趣的朋友可以自取,出于一些原因不多作解释,权当自娱。近期限于各种原因的制约暂时搁置,以后有条件再继续完善这个项目。 代码文件结构如下所示👇 ../ > FC_crawl.py > FC_hparams.py > FC_utils.py > ../FC_music/ > __init__.py > music_analysis.py > music_netease.py > music_qq.py > music_kuwo.py 除了 __init__.py 是个空文件外,其他七个文件都在下文中可以取得,目前使用时 music_kuwo.py , music_netease.py , music_qq.py 都可以单独运行,截至本文发布都可以正常运行,特别地, music_netease.py , music_qq.py 可能需要安装 selenium (基于 Firefox 版本)和 Crypto 库(这个库安装的话请直接安装 pycryptodome 即可,如果安装 Crypto 会有些不友好的问题)。 代码注释很详细,本意在 FC_music 模块下准备做个音频分析,其他模块暂时还没有想法,但是转念一想 PC 机的磁盘上最多能存一万个的 mp3 音频文件,感觉也没什么意义,而且 mp3 格式的文件本来也不能直接进行音频分析,都必须要转成 wav

TypeError: decrypt() cannot be called after encrypt()

风格不统一 提交于 2020-06-27 21:37:39
问题 I am writing a simple code of AES encryption. I got stuck at a part where it says decrypt() cannot be called after encrypt(). I scrapped through the internet to find the solution, but unable to do so, maybe because of the lack of proper documentation examples. I tried changing the sequence these lines, but it did not help encrypted = encrypt(message) decrypted = decrypt(encrypted) I have 2 examples Example1 from Crypto.Cipher import AES key = 'ACD310AE179CE245624BB238867CE189' message = 'this

TypeError: decrypt() cannot be called after encrypt()

这一生的挚爱 提交于 2020-06-27 21:35:36
问题 I am writing a simple code of AES encryption. I got stuck at a part where it says decrypt() cannot be called after encrypt(). I scrapped through the internet to find the solution, but unable to do so, maybe because of the lack of proper documentation examples. I tried changing the sequence these lines, but it did not help encrypted = encrypt(message) decrypted = decrypt(encrypted) I have 2 examples Example1 from Crypto.Cipher import AES key = 'ACD310AE179CE245624BB238867CE189' message = 'this