
I have 5 stored on my card I think it is the only one that is currently valid but I suppose it might be an older one. User need to choose the appropriate store. You need to call LoadCertificate from the above code. I have played around with it a little bit.

Note the call to Decrypt on the RSACryptoServiceProvider automatically loads the above dialog - Assuming that the right certificate is choosen. RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)x509.PrivateKey īyte bytestodecrypt = Convert.FromBase64String(stringTodecrypt) īyte plainbytes = rsa.Decrypt(bytestodecrypt, false) Throw new Exception("x509 certicate does not contain a private key for decryption") Throw new Exception("A x509 certificate and string for decryption must be provided") If (x509 = null || string.IsNullOrEmpty(stringTodecrypt)) Public static string Decrypt(X509Certificate2 x509, string stringTodecrypt) Return Convert.ToBase64String(encryptedBytes) RSACryptoServiceProvider rsa = (RSACryptoServiceProvider) īyte bytestoEncrypt = (stringToEncrypt) īyte encryptedBytes = rsa.Encrypt(bytestoEncrypt, false)

Throw new Exception("A x509 certificate and string for encryption must be provided") If (x509 = null || string.IsNullOrEmpty(stringToEncrypt))

Public static string Encrypt(X509Certificate2 x509, string stringToEncrypt) String decryptedstring = Decrypt(x509_2, encryptedstring) Ĭonsole.WriteLine("decrypted text: " + decryptedstring + Environment.NewLine) Ĭonsole.WriteLine("Error: ",Environment.NewLine,(false))
