问题标签 [pycrypto]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
9965 浏览

python - 我有模数和私人指数。如何构造 RSA 私钥并签署消息?

我是密码学和pycrypto的新手。

我有模数n和私有指数d。根据我在阅读一些文档后的理解,私钥n和组成d

我需要签署一条消息,但我不知道如何使用pycrypto. RSA.construct()方法接受一个元组。但是我必须另外提供e这种方法的公共指数(我没有)。

所以这是我的问题。我是否必须以e某种方式计算才能签署消息?

看来我应该能够通过使用nd(构成私钥)来签署消息。我对么?我可以这样做pycrypto吗?

提前致谢。

0 投票
1 回答
9776 浏览

python - 如何在 64 位 Windows 7 机器上安装 pycrypto?

我尝试使用 安装 PyCrypto pip,但它抱怨需要 vcvarsall.bat。我安装了 Visual Studio 2008,但现在ValueError: [u'path']当我尝试从pip.

我尝试从Voidspace下载预构建的二进制文件,但它们只有 32 位版本,而且它似乎没有正确安装在我的机器上(它说它成功,但运行 python 并尝试import Crypto给我一个ImportError: No module named Crypto.

我需要做什么?

0 投票
1 回答
3375 浏览

python - Python AES encoding/decoding string and storing in MySQL

I'm working on a project using Pyramid 1.3 (Python 2.7) and storing data in MySQL. I have a table of email addresses, and I would like to encrypt them for storage. I am trying to encrypt them in the application, and then will decrypt them for viewing. I'm not going for complete security but am mainly aiming to obfuscate the data enough were the database itself compromised.

I'm using PyCrypto with AES, and have been trying to follow some posts on here and some web tutorials I found. The closest I found so far is this post, and it seems to work, at least encrypting it. I follow that and get something like "7hBAQrWhJRnL9YdBGJfRErGFwGi3aC6noGzYTrGwAoQ=" stored in the database. But the decrypt function keeps erroring with this:

I came across some unicode presentation about Python which sort of helped me make more sense of it but I still keep getting the same error.

Is there a straightforward tutorial on how to encode, store in a database, pull out of database, and decode a source data string?

Do I need a specific collation on the database column? Does the field need to be a certain type? So far I've been using a default collation and setting it to VARCHAR, assuming that I was storing a string. It sounds like I've got some encoding problem somewhere with incompatible types or something but my head is spinning on where I need to change something.

Any better pointers or anything else I can provide? I can show my code but its basically a copy of the link above... I was just trying to get a proof of concept working before modifying it too much.

edit: some sample source... In MySQL, the table is id (int) client_id (int) emailaddress varchar(100) utf8mb4_general_ci (I've been playing around with the collations, I have no idea what it should be!)

Python:

clientemails is the list of emails from the table above. I get the error when uncommenting out:

I was just trying to decode the first item just to try and get it to work but that's the part that seems to be giving it fits now....

0 投票
2 回答
4044 浏览

java - 在python中对javax.crypto编码的字符串进行Blowfish解密

使用在https://raw.github.com/usefulfor/usefulfor/master/security/JBoss.java找到的代码,我做了以下事情:

但是,我一辈子都无法弄清楚如何在 python 中使用 pycrypto 解密字符串 '27038292d345798947e2852756afcf0a'。我的理解是 Java 代码使用 Blowfish,而短语“jaas is the way”作为密码的关键。但我无法理解如何在 python 中执行此操作。以下结果大多是不可打印的垃圾:

我错过了什么?

谢谢。

0 投票
1 回答
6653 浏览

python - 在 Windows 上通过 pip 使用 fastmath(gmp 或 mpir)构建 PyCrypto

我通过 pip 在 Windows 上安装了 PyCrypto,但由于找不到 GMP,我无法构建 Crypto.PublicKey._fastmath。

我知道voidspace上有一个二进制版本,但我想构建最新版本的 PyCrypto

0 投票
2 回答
12473 浏览

python - 在 Python 3 中使用 AES 和 PyCrypto 加密文件

我正在使用 PyCrypto 在 CBC 模式下使用 AES 加密二进制文件(Python 3.2.3 64 位和 PyCrypto 2.6)。使用以下代码:http ://eli.thegreenplace.net/2010/06/25/aes-encryption-of-files-in-python-with-pycrypto/

但遇到以下错误:ValueError: IV must be 16 bytes long。

这是代码:

我已经尝试过搜索和试验,但似乎无法让它发挥作用。Python 对我来说很新,加密也是。任何帮助将不胜感激。提前致谢。

0 投票
2 回答
1349 浏览

google-app-engine - 在 Google App Engine 上的 dev_appserver.py 中导入 pycrypto 会产生 IOError

我正在尝试使用 测试 Google App Engine 应用程序dev_appserver.py,但是当我运行时,我import CryptoIOError(即无访问权限)回溯中摘录了以下内容:

我在 Mac OS X 10.7 上,使用 Python 2.7 和 Google App Engine 1.6.6。

由于Google App Engine 支持PyCrypto ,我希望它可以在开发服务器上运行。

我知道这会dev_appserver.py阻止加载外部文件。但是,我注意到appengine/tools/dev_appserver_import_hook.py白名单中似乎包含所有必需的文件(例如_fastmath)。

注意,在app.yaml我有

似乎我遗漏了一些明显但至关重要的东西。任何想法将不胜感激。


编辑有关更多详细信息,请参阅:https ://code.google.com/p/googleappengine/issues/detail?id=12129

0 投票
1 回答
2240 浏览

python - Google App Engine 开发服务器中的 PyCrypto “ImportError: cannot import name blockalgo”

我有一个使用 PyCrypto 使用 AES 加密字符串的函数。当我在单元测试中调用该函数时,一切正常。在生产环境中,它也可以正常工作。但是,在 GAE 开发服务器上调用该函数时,会抛出错误:“ImportError: cannot import name blockalgo”。我在 Windows 7(64 位)和 Mac OS 10.5 上对其进行了测试。两者都导致相同的错误。我正在使用带有 Python 2.7 的 Google App Engine。可能是什么问题呢?

应用程序.yaml

加密功能:

0 投票
1 回答
1057 浏览

python - Google App Engine + PyCrypto = /dev/urandom 无法访问

我正在使用 Google App Engine 和 PyCrypto 进行一些加密。我得到的错误如下所示,仅发生在运行 Linux Mint Maya (13)的本地开发服务器上。我将相同的代码部署到 GAE 云中,它运行时没有错误。

引发错误的 python 代码是此块中的第二行:

看到这个错误后,我意识到这可能是一个权限错误。于是我快速检查了 /dev/urandom 的权限:

所以看起来我的权限很好。我也尝试过以 root 身份运行开发服务器,但我得到了同样的错误。由于某种原因,这只发生在开发服务器上,而不是部署到谷歌的云上。关于下一步尝试什么的任何想法?

谢谢!

0 投票
1 回答
1370 浏览

java - Java Python 消息签名和验证

我的服务器是用 Python 编码的,我正在为这个服务器制作一个 java 客户端。

我正在使用以下方式签署消息(数据):

这将返回一个 byteArray(named signed_data) ,现在我正在使用 Base64.encodeBase64 对该签名进行编码,并使用以下方法将 byteArray(named my_byte_array) 转换为字符串:

并将此字符串发送到服务器。

在服务器端,我收到这个字符串,然后服务器使用以下方法验证签名:

使用库http://gdata-python-client.googlecode.com/hg/pydocs/gdata.Crypto.PublicKey.RSA.html

当我尝试在两侧打印 my_byte_array 时,它们是相同的,signed_data 和 base64.b64decode(my_byte_array) 也是如此

但我收到此错误:

据我所知,之所以会出现此错误,是因为 Java 将消息签名为字节,而 python 期望它为 Long。

有没有办法解决这个问题?