Is there a way to encrypt a secret key in C #?
I know about the RSACryptoServiceProvider standard in System.Security.Cryptography , but these classes only provide public key encryption and private key decryption . In addition, they provide digital signature functionality that uses internal encryption with the private key , but there are no public functions to perform encryption of the private key and public key .
I found this article on codeproject , which is a very good starting point for performing this kind of encryption, however I was looking for ready-to-use code, since the code in the article is unlikely to encrypt arrays of arbitrarily long bytes containing random values โโ(this means any values, including zeros).
Do you know some good components (preferably free) to perform private key encryption ?
I am using .NET 3.5 .
Note: I know that this is usually considered the wrong way to use asymmetric encryption (encryption using the private key and decryption using the public key), but I just need to use it that way.
Additional explanation
You have
var bytes = new byte[30] { };
and you want to use 2048bit RSA so that no one changes anything in this array.
Usually you should use a digital signature (i.e. RIPEMD160 ), which you then attach to the original bytes and send to the recipient.
So, you have 30 bytes of source data and an additional 256 bytes of digital signature (since this is 2048bit RSA ), which generally corresponds to 286 bytes . Hovewer, only 160 bits of this 256 bytes is actually a hash, so there are exactly 1888 bits ( 236 bytes ) not used.
So my idea is this:
Take 30 bytes of source data, attach a hash ( 20 bytes ) to it, and now encrypt these 50 bytes . You get a long message of 256 bytes , which is much shorter than 286 bytes , because "you were able to click the actual data inside the digital signature."
ECDSA Resources
MSDN
Eggheadcafe.com
c-plusplus.de
MSDN Blog
Wiki
DSA Resources
CodeProject
MSDN 1
MSDN 2
MSDN 3
Final decision
If someone is interested in how I solved this problem, I will use 1024bit DSA and SHA1 , which is widely supported in many different versions of Windows ( Windows 2000 and newer), the security is good enough (I do not sign orders, I just need to make sure that some child cannot crack the signature on his iPhone (:-D)), and the signature size is only 40 bytes .