如何使用RSA公钥解密数据?
让我介绍一下我的问题,我有一些 *.crt 文件,其中包含 DER 编码的 x509 版本 3 证书。我使用 ASN1 DER(libtomcrypt) 解密数据并将其保存到名为 x509v3
的结构中。 我有一些消息M,M的加密签名-> S(RSA加密),和公钥-> P 位于 x509 证书(主题公钥字段)内。首先我必须使用公钥 P 解密 S,但问题是我找不到任何可以执行此操作的 api?
我寻找了 libtomcrypt 但似乎没有 api 接受公钥(即 unsigned char * )和加密数据(也是 unsigned char * )并给出解密数据( unsigned char * )。
感谢您的帮助! PS抱歉我的英语;)
let me introduce my problem, i have some *.crt file, which contains DER encoded x509 version 3 certificate. Using ASN1 DER(libtomcrypt) i decrypt data and save it to some structure called x509v3
.
I have some message M, encrypted signature of M -> S(RSA encrypted), and public key -> P which is located inside x509 certificate(subject public key field). First i must decrypt S using public key P, but problem is that i can't find any api which will do this?
I looked for libtomcrypt but seems there is no api which takes public key( which is unsigned char * ) and encrypted data (also unsigned char *) and gives the decrypted data( unsigned char *).
Thanks for help!
p.s. sorry for my english;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是历史上草率签名的无数受害者之一,这种草率的签名已经造成并且仍然造成大量的混乱。
您拥有的是一个签名,并且您想要验证它。存在多种签名算法,其中一种称为“RSA”,因为它看起来类似于非对称加密算法也称为相似。 RSA签名的一个非常粗略的描述是“你用私钥加密”(即以“相反”方向采取加密算法),这就是为什么签名经常被这样描述......只不过它并没有真正起作用像这样。 RSA 的非对称加密意味着其核心是数学运算(模幂),但同时也是对安全性非常重要的“填充”; RSA 签名还意味着填充,但这是一种非常独特的填充。
所以你真的不应该将签名视为一种加密。这只会让你感到困惑。
在libtomcrypt中,RSA签名验证函数称为rsa_verify_hash()。
You are one of the countless victims of an historical sloppy presentation of signatures, which has created and still creates massive amounts of confusion.
What you have is a signature and you want to verify it. There exist several signature algorithms, and one of them is called "RSA" because it looks similar to an asymmetric encryption algorithm also called similar. A very rough description of RSA signatures is that "you encrypt with the private key" (i.e. taking the encryption algorithm in the "reverse" direction), which is why signatures are often described like this... except that it does not really work like this. Asymmetric encryption with RSA implies a mathematical operation (modular exponentiation) at its core, but also a "padding" which is very important for security; RSA signatures also imply a padding, but a quite distinct one.
So you really should not think about signatures as a kind of encryption. This will just confuse you.
In libtomcrypt, the RSA signature verification function is called
rsa_verify_hash()
.