How do you verify an RSA SHA1 signature in Python?(如何在 Python 中验证 RSA SHA1 签名?)
问题描述
我有一个字符串、一个签名和一个公钥,我想验证字符串上的签名.密钥如下所示:
I've got a string, a signature, and a public key, and I want to verify the signature on the string. The key looks like this:
我已经阅读 pycrypto 文档有一段时间了,但我不知道如何使用这种密钥制作 RSAobj.如果您了解 PHP,我正在尝试执行以下操作:
I've been reading the pycrypto docs for a while, but I can't figure out how to make an RSAobj with this kind of key. If you know PHP, I'm trying to do the following:
另外,如果我对任何术语感到困惑,请告诉我.
Also, if I'm confused about any terminology, please let me know.
推荐答案
标记之间的数据是包含 PKCS#1 RSAPublicKey 的 PKCS#8 PublicKeyInfo 的 ASN.1 DER 编码的 base64 编码.
The data between the markers is the base64 encoding of the ASN.1 DER-encoding of a PKCS#8 PublicKeyInfo containing an PKCS#1 RSAPublicKey.
这是很多标准,最好使用加密库对其进行解码(例如 M2Crypto 作为 joeforker 建议).将以下内容视为有关格式的一些有趣信息:
That is a lot of standards, and you will be best served with using a crypto-library to decode it (such as M2Crypto as suggested by joeforker). Treat the following as some fun info about the format:
如果你愿意,你可以这样解码:
If you want to, you can decode it like this:
Base64 解码字符串:
Base64-decode the string:
这是 DER 编码:
对于 1024 位 RSA 密钥,您可以将 "30819f300d06092a864886f70d010101050003818d00308189028181"
视为常量标头,后跟 00 字节,然后是 RSA 模数的 128 字节.在那之后 95% 的时间你会得到 0203010001
,这表示 RSA 公共指数 0x10001 = 65537.
For a 1024 bit RSA key, you can treat "30819f300d06092a864886f70d010101050003818d00308189028181"
as a constant header, followed by a 00-byte, followed by the 128 bytes of the RSA modulus. After that 95% of the time you will get 0203010001
, which signifies a RSA public exponent of 0x10001 = 65537.
您可以将这两个值用作元组中的 n
和 e
来构造 RSAobj.
You can use those two values as n
and e
in a tuple to construct a RSAobj.
这篇关于如何在 Python 中验证 RSA SHA1 签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!