public void GeneratePrivateKetTest() { RsaCryptoService.GeneratePrivateKey(FullPath); Assert.That(File.Exists(FullPath), Is.True); Console.Out.WriteLine(File.ReadAllText(FullPath)); }
/// <summary> /// 对密文进行解密 /// </summary> /// <param name="encryptedStr"></param> /// <returns></returns> private string DecryptStr(string encryptedStr) { var path = Server.MapPath("~/config/keys.config"); var privateKey = new XmlHelper(path).GetValue("privateKey").Trim(); var rsa = new RsaCryptoService(privateKey); var decryptStr = rsa.Decrypt(encryptedStr); return(decryptStr); }
public void EncryptDecryptDataTest() { RsaCryptoService.GeneratePrivateKey(FullPath); string data = "123456789"; string encryptData = _rsaCryptoService.EncryptData(FullPath, data); Console.Out.WriteLine("Password: " + encryptData); string decryptData = _rsaCryptoService.DecryptData(FullPath, encryptData); Assert.That(data, Is.EqualTo(decryptData)); }
public void SetUp() { _rsaCryptoService = new RsaCryptoService(); string path = Path.Combine(RootPath, TestDirectory); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (File.Exists(FullPath)) { File.Delete(FullPath); } }