I\'m trying to make a password safe, but theres something wrong with how I use RSA. Heres my codes:
private void testencodedecode()
{
string mehd
There are some major issues with the method here. The first, as you mentioned in a comment on another answer is that you're using a Guid
to construct the RSA modulus, which is entirely invalid. You cannot use random data to construct the public key directly for a number of reasons:
Guid
in binary form generally will not be.You should be generating the RSA key using the RsaCryptoServiceProvider
constructor e.g.:
// Construct the RsaCryptoServiceProvider, and create a new 2048bit key
var csp = new RsaCryptoServiceProvider(2048);
The parameters for this newly generated key can then be exported:
// Export the RSA parameters, including the private parameters
var parameters = csp.ExportParameters(true);
The parameters can then be stored (securely) and used to re-initialize the CSP for decryption later.
There are also other obvious problems, such as the fact that the amount of data you can actually encrypt with RSA is limited by the key size, so with a 2048 bit key as created above, you can encrypt 2048 / 8 - 11 = 245 bytes (where the 11 bytes is a result of the PKCS#1 v1.5 padding that is applied). If you want to encrypt more than this, the general method is to use a symmetric cipher (e.g. AES) to encrypt the data, and then use RSA only to encrypt the AES key.
Finally, whilst this may work, I still wouldn't rely on it for security as there are almost always issues with roll-your-own encryption schemes.