简体   繁体   English

使用RSA公钥签名字符串

[英]Sign String With RSA Public Key

Let's say I have generated private and public key RSA pair with this command: 假设我使用以下命令生成了私钥和公钥RSA对:

ssh-keygen -t rsa -C "your_email@example.com"

I have found this Python library which can use RSA key to sign a message: 我发现此Python库可使用RSA密钥对消息进行签名:

http://stuvel.eu/files/python-rsa-doc/usage.html#signing-and-verification http://stuvel.eu/files/python-rsa-doc/usage.html#signing-and-verification

It does not have methods to read the key from a file though. 它没有方法从文件中读取密钥。 How can I do that? 我怎样才能做到这一点?

Any other library you would recommend? 您会推荐其他图书馆吗?

Basically, I want to sign all API requests coming from an app to my web service to make sure nobody else can use my APIs. 基本上,我想将所有来自应用程序的API请求签名到我的Web服务,以确保没有其他人可以使用我的API。

ssh-keygen generates PEM files which can be accessed (according to the link you gave) like this: ssh-keygen生成可通过以下方式访问(根据您提供的链接)的PEM文件:

$ cd ~/.ssh
$ python
>>> import rsa
>>> with open('id_rsa') as privatefile:
...     keydata = privatefile.read()
>>> privkey = rsa.PrivateKey.load_pkcs1(keydata)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM