public static String EncryptData(string data2Encrypt) { EZRSA rsa; rsa = new EZRSA(1024); rsa.FromXmlString(publicKeyString); byte[] plainbytes = System.Text.Encoding.UTF8.GetBytes(data2Encrypt); byte[] cipherbytes = rsa.Encrypt(plainbytes, false); string base64String = Convert.ToBase64String(cipherbytes); return HttpUtility.UrlEncode(base64String); }
public static string DecryptData(string data2Decrypt) { //string urlDecodeData = HttpUtility.UrlDecode(data2Decrypt); EZRSA rsa; rsa = new EZRSA(1024); rsa.FromXmlString(privateKeyString); byte[] getpassword = Convert.FromBase64String(data2Decrypt); byte[] plain = rsa.Decrypt(getpassword, false); return System.Text.Encoding.UTF8.GetString(plain); }
public void SaveWithSignature(string fileName, string keyFileName) { EZRSA rsa = new EZRSA(1024); //rsa.MapHashAlgorithmOID( if (File.Exists(keyFileName)) { StreamReader sr = File.OpenText(keyFileName); string str = sr.ReadToEnd(); rsa.FromXmlString(str); sr.Close(); XmlDocument doc = SaveWithSignature(rsa); doc.Save(fileName); } // TODO: exception /*else { int poo; }*/ }
public XmlDocument SaveWithSignature(string keyFileName) { // CspParameters cspParams = new CspParameters(); // cspParams.Flags = CspProviderFlags.UseExistingKey; // RSA rsa = new RSACryptoServiceProvider(cspParams); EZRSA rsa = new EZRSA(1024); rsa.FromXmlString(File.ReadAllText(keyFileName)); return SaveWithSignature(rsa); }