Hey,can you help me?
I want to encrypt text, when my private key is in the privat.xml file. My code doesn't work.
Thank you so much for help and your time.
What I have tried:
private void button2_Click(object sender, EventArgs e)
{
// convert the string into byte array
byte[] str = ASCIIEncoding.Unicode.GetBytes(textBox1.Text);
// read the private key
string privat = System.IO.File.ReadAllText(@"C:\Users\Gretaa\Desktop\RSA\privat.xml");
// compute the hash with any hash algorithm
SHA1Managed sha1hash = new SHA1Managed();
byte[] hashdata = sha1hash.ComputeHash(str);
// sign the hash data with private key
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(privat);
// signature hold the sign data of plaintext , signed by private key
byte[] signature = rsa.SignData(str, "SHA1");
textBox14.Text = signature.ToString();
}