Pycrypto [英] Pycrypto

查看:89
本文介绍了Pycrypto的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我必须轻松操作但是阅读pycrypto doc。 a never

参见AES示例

我必须使用

AES来压缩这个键''ea523a664dabaa4476d31226a1e3bab0'。

你能用pycrypto来帮助我吗


问候Luca

Hello
I have to make an easy operation but reading the pycrypto doc. a never
see AES example
I have to cript this key ''ea523a664dabaa4476d31226a1e3bab0'' with the
AES.
Can you help me for make it with pycrypto

Regards Luca

推荐答案

luca72写道:
你好
我必须做一个简单的操作,但阅读pycrypto文档。一个永远不会看到AES的例子
我必须用
AES来解决这个关键词''ea523a664dabaa4476d31226a1e3bab0'。
你能用pycrypto来帮助我吗?
<问候卢卡
Hello
I have to make an easy operation but reading the pycrypto doc. a never
see AES example
I have to cript this key ''ea523a664dabaa4476d31226a1e3bab0'' with the
AES.
Can you help me for make it with pycrypto

Regards Luca




你可以这样做:


py>来自Crypto.Cipher导入AES

py>对于AES,#key必须是16,24或32字节

py> crypt = AES.new(''abcdefghijklmnop'',AES.MODE_ECB)

#我们很幸运,要加密的字符串是16的倍数

PY> txt =''ea523a664dabaa4476d31226a1e3bab0''

py> c = crypt.encrypt(txt)

py> c

''w\x81 \ xe3 \ xdd \ x066 \ x9eY \ xc7 \ xce~O \\\ x9e \\ xxb \ xef \ xx \ xb5 \ x8a \ xac \ x7f \ xca \ x9fl {\xe5 \xfd6 \ x80 \ xe3 \ x81%\ x b9''

py> crypt.decrypt(c)

''ea523a664dabaa4476d31226a1e3bab0''


http://www.amk.ca/python/writing/pycrypt 文档。如果你有

来加密没有长度为16的倍数的数据,你必须填写

,例如使用空格,然后去掉decrypt()结果。



You can do this as follows:

py> from Crypto.Cipher import AES
py> # key has to be 16, 24 or 32 bytes for AES
py> crypt = AES.new(''abcdefghijklmnop'', AES.MODE_ECB)
# we''re lucky, the string to encrypt is a multiple of 16 in length
py> txt = ''ea523a664dabaa4476d31226a1e3bab0''
py> c = crypt.encrypt(txt)
py> c
''w\x81\xe3\xdd\x066\x9eY\xc7\xce~O\x9e\xfb\xef\xfa \xb5\x8a\xac\x7f\xca\x9fl{\xe5\xfd6\x80\xe3\x81%\x b9''
py> crypt.decrypt(c)
''ea523a664dabaa4476d31226a1e3bab0''

see http://www.amk.ca/python/writing/pycrypt for the docs. if you have
to encrypt data which has not a multiple of length 16 you have to pad
it e.g. with spaces, and then strip the decrypt() result.


您可以按如下方式执行此操作:

py>来自Crypto.Cipher导入AES
py>对于AES,#key必须是16,24或32字节
py> crypt = AES.new(''abcdefghijklmnop'',AES.MODE_ECB)
#我们很幸运,要加密的字符串是16的长度的倍数
py> txt =''ea523a664dabaa4476d31226a1e3bab0''
py> c = crypt.encrypt(txt)
py> c
''w \ x81 \ xe3 \ xdd \ x066 \ x9eY \ xc7 \ xce~ \\\ x \\ xac \ x7f \ xca \ x9fl {\ xe5 \ xfd6 \ x80 \ xe3 \ x81%\ x b9''
py> crypt.decrypt(c)
''ea523a664dabaa4476d31226a1e3bab0''

http://www.amk.ca/python/writing/pycrypt 。如果你有加密长度为16的倍数的数据,你必须填写它,例如用空格,然后去掉decrypt()结果。
You can do this as follows:

py> from Crypto.Cipher import AES
py> # key has to be 16, 24 or 32 bytes for AES
py> crypt = AES.new(''abcdefghijklmnop'', AES.MODE_ECB)
# we''re lucky, the string to encrypt is a multiple of 16 in length
py> txt = ''ea523a664dabaa4476d31226a1e3bab0''
py> c = crypt.encrypt(txt)
py> c
''w\x81\xe3\xdd\x066\x9eY\xc7\xce~O\x9e\xfb\xef\xfa \xb5\x8a\xac\x7f\xca\x9fl{\xe5\xfd6\x80\xe3\x81%\x b9''
py> crypt.decrypt(c)
''ea523a664dabaa4476d31226a1e3bab0''

see http://www.amk.ca/python/writing/pycrypt for the docs. if you have
to encrypt data which has not a multiple of length 16 you have to pad
it e.g. with spaces, and then strip the decrypt() result.



或者使用CBC模式?我不熟悉pycrypto,但我知道CBC模式

可以加密/解密任何大小的文本。


Laszlo


Or use CBC mode? I''m not familiar with pycrypto but I know that CBC mode
can crypt/decrypt text with any size.

Laszlo




Laszlo Nagy写道:

Laszlo Nagy wrote:
你可以这样做:

py>来自Crypto.Cipher导入AES
py>对于AES,#key必须是16,24或32字节
py> crypt = AES.new(''abcdefghijklmnop'',AES.MODE_ECB)
#我们很幸运,要加密的字符串是16的长度的倍数
py> txt =''ea523a664dabaa4476d31226a1e3bab0''
py> c = crypt.encrypt(txt)
py> c
''w \ x81 \ xe3 \ xdd \ x066 \ x9eY \ xc7 \ xce~ \\\ x \\ xac \ x7f \ xca \ x9fl {\ xe5 \ xfd6 \ x80 \ xe3 \ x81%\ x b9''
py> crypt.decrypt(c)
''ea523a664dabaa4476d31226a1e3bab0''

http://www.amk.ca/python/writing/pycrypt 。如果你有加密长度为16的倍数的数据,你必须填写它,例如使用空格,然后去掉decrypt()结果。
You can do this as follows:

py> from Crypto.Cipher import AES
py> # key has to be 16, 24 or 32 bytes for AES
py> crypt = AES.new(''abcdefghijklmnop'', AES.MODE_ECB)
# we''re lucky, the string to encrypt is a multiple of 16 in length
py> txt = ''ea523a664dabaa4476d31226a1e3bab0''
py> c = crypt.encrypt(txt)
py> c
''w\x81\xe3\xdd\x066\x9eY\xc7\xce~O\x9e\xfb\xef\xfa \xb5\x8a\xac\x7f\xca\x9fl{\xe5\xfd6\x80\xe3\x81%\x b9''
py> crypt.decrypt(c)
''ea523a664dabaa4476d31226a1e3bab0''

see http://www.amk.ca/python/writing/pycrypt for the docs. if you have
to encrypt data which has not a multiple of length 16 you have to pad
it e.g. with spaces, and then strip the decrypt() result.


或使用CBC模式?我不熟悉pycrypto,但我知道CBC模式可以加密/解密任何大小的文本。

Laszlo


Or use CBC mode? I''m not familiar with pycrypto but I know that CBC mode
can crypt/decrypt text with any size.

Laszlo




不在此实现中:

py>来自Crypto.Cipher导入AES

py> crypt = AES.new(''abcdefghijklmnop'',AES.MODE_CBC)

py> c = crypt.encrypt(''1'')

Traceback(最近一次调用最后一次):

文件"< stdin>",第1行,in ?

ValueError:输入字符串的长度必须是16的倍数



Not in this implementation:
py> from Crypto.Cipher import AES
py> crypt = AES.new(''abcdefghijklmnop'', AES.MODE_CBC)
py> c = crypt.encrypt(''1'')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: Input strings must be a multiple of 16 in length


这篇关于Pycrypto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆