开发者

RSA: how to generate RSA public and private keys based on a passphrase (.net)

开发者 https://www.devze.com 2023-02-19 04:39 出处:网络
I\'m working in .net environment (all versions) and using vb.net. I wa开发者_如何学Pythonnt to generate RSA public and private keys based on a passphrase.

I'm working in .net environment (all versions) and using vb.net. I wa开发者_如何学Pythonnt to generate RSA public and private keys based on a passphrase.

My understanding of RSA algorithm only limited by using a class provided by the .net ie System.Security.Cryptography.RSACryptoServiceProvider Class. I know how to generate random RSA public/private keys and perform encryption/decryption.

But that .net class don't let us creating RSA public/private keys based on a passphrase.

Although I'm using vb.net, anyone with solutions in c#, c, c++ or any .net compatible language are welcomed to contribute as I can access the solution via p/invoke or dll reference.

Thanks in advance!


Perhaps you should consider symmetric key encryption like AES, where a passphrase would make sense to derive a key from. You mentioned this is for internal use, do you really need RSA? If so perhaps what you want to do is protect the RSA private key file, which you could do by AES encrypting that file and using a passphrase for the key to that. You should always generate RSA public/private key pairs with software that's intended to do it.


Considering that you need roughly 2048 bits of randomness in order to start your primality tests (1024 bits on each potential-prime), and that your potential-primes may fail their primality tests, your passphrases would need to be very long to provide enough entropy to generate good keys.

Lets assume that there are roughly 94 keys on the keyboard that generate characters, and further assume that users will actually hit them at random. (Not a good assumption, but bear with me.)

That's log(94)/log(2) == 6.55 bits of entropy per character. To get 2048 bits of entropy, you'll need to ask for a passphrase that is 313 characters long: 2048 / 6.55... == 312.45.

How do you think your users will feel about being asked for a 300+ character passphrase? And remember, this is under the optimistic assumption that users will hit each of the 94 symbols at random; this seems vastly unlikely to me. I think 40-odd characters is going to be the real limit of people's creativity: 26 letters, 10 digits, and the punctuation keys that don't require shift. That'd be around 384 characters in your passphrase.

Please just stick to randomly-generated keys, where someone very clever is in charge of collecting the entropy to seed the pseudo-random-number generator.


You won't need RSA if you don't need public key encryption.

Use symmetrical encryption with password-based key derivation function (e.g. AES with PBKDF2). It will be faster and more secure.


As far as I know, Rsa keys are never based on a passphrase. You can only protect the rsa keys with a passphrase.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号