根据字符串生成密钥对 [英] generate key pair based on a string

查看:808
本文介绍了根据字符串生成密钥对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个基于字符串的私人密钥。 (这个字符串是在运行时生成的独特的特定于机器的id,公共密钥将被共享,所以所有用户都可以将数据发送到本机。)

I need to create private\public key based on a string. (This string is unique machine-specific id generated at runtime. Public key will be shared, so all users could send the data to this machine.)

就我而言知道,RSACryptoServiceProvider会自动生成密钥对。每次发送相同的字符串时,我需要生成相同的对。

As far as I know, RSACryptoServiceProvider generates the key pair automatically. I need to generate the same pair each time I send the same string.

任何想法如何在c#中实现?

Any idea how to implement this in c#?

(添加)
我不是有兴趣创建证书并在本地存储,这在这种情况下不适用(因为如果在计算机上的两个不同的os安装中生成一个证书,那么密钥对将是不同的,我需要特定于机器的ID和密钥对现在如何生成ID,但我不知道如何生成密钥的基础上)。

(added) I'm not interested in creating a certificate and storing it locally, it doesn't suit in this case (because if you generate a cerificate in two different os installations on a computer, the keypairs will be different. I need machine-specific ID and keypair. I now how to generate ID, but I'm not sure yet how to generate keys base on it).

我想使用RSA,但是任何非对称算法都是合适的。

I'd like to use RSA, however, any asymmetric algorithm will be suitable.

推荐答案

您可以尝试以下操作:

使用 Rfc2898DeriveBytes 来导出两个bitstrings。将每个部分解释为一个BigInteger,然后找到下一个素数。这些是您可以构建您用于RSA的e,d,n的p,q。。
但是,由于我刚才发明了这个可能是一个坏主意,它不是基于已建立的加密技术。

You could try the following:
Use Rfc2898DeriveBytes to derive two bitstrings. Interpret each part as one BigInteger, and find the next prime after it. These are your p,q from which you can construct your e,d,n used for RSA.
But this is probably a bad idea since I just invented it, and it's not based on established cryptography.

我宁愿在每台计算机上以正常的方式生成一个私钥,并存储它。我认为Windows甚至提供了一种特殊的方式存储密钥。

I'd rather generate a private key in a normal way on each computer, and store it. I think windows even offers a special way to store keys.

这篇关于根据字符串生成密钥对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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