public static RSACryptoServiceProvider DecodeRsaPrivateKey(string privateKey,string password="")
{
Dictionary<string, string> extras = new Dictionary<string, string>();
byte[] bytes = Helpers.GetBytesFromPEM(privateKey, out extras);
if (extras.Any(x => x.Value.Contains("ENCRYPTED")) && extras.Any(x => x.Key.Contains("DEK-Inf")))
{
String saltstr = extras.First(x => x.Key.Contains("DEK-Inf")).Value.Split(',')[1].Trim();
byte[] salt = new byte[saltstr.Length / 2];
for (int i = 0; i < salt.Length; i++)
salt[i] = Convert.ToByte(saltstr.Substring(i * 2, 2), 16);
SecureString despswd = new SecureString(); // GetSecPswd("Enter password to derive 3DES key==>");
foreach (char c in password)
despswd.AppendChar(c);
byte[] decoded = DecryptRSAPrivatePEM(bytes, salt, despswd);
bytes = decoded;
}
return DecodeRsaPrivateKey(bytes);
}