The general principle is:
How to implement this principle of encryption?
I get a pair of Rsa keys:
Code
Get a pair of RSA keys.
This is a pair of constant.
For the file, get the AES key.
This key is one-time and only applies to this file.
Encrypt AES key with RSA public key.
The encrypted block is always aligned to the same size.
Create a new file.
Write to it consistently: the encrypted AES key and information
AES encrypted key.
To read opens the file with the encrypted key and information. Reads an AES encrypted key.
Decrypt it with the RSA private key.
With the received key you decrypt the remaining information.I get a pair of Rsa keys:
Code
// Getkey(true); or Getkey(false);
public string GetKey(bool choice)
{
string key = null;
try
{
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048))
{
if (choice)
{
key = rsa.ToXmlString(false);
}
else
{
key = rsa.ToXmlString(true);
}
}
}
catch (CryptographicException) { }
return key;
}
