private void 解密资源文本ToolStripMenuItem_Click(object sender, EventArgs e) { var op1 = new OpenFileDialog(); op1.CheckFileExists = false; op1.Filter = "all file (*.*)|*.*"; op1.FileName = "all txt here"; if (op1.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(op1.FileName)) { var dir = Path.GetDirectoryName(op1.FileName); var outdir = dir + "_dec"; var fls = Directory.GetFiles(dir, "*.txt", SearchOption.TopDirectoryOnly); foreach (var fl in fls) { var str = File.ReadAllText(fl); var bytes = Convert.FromBase64String(str); var decoder = new RijndaelCryptography(); GenerateKeyFromPassword("BSZ.TGL.XML", decoder.KeySize, out byte[] key, decoder.BlockSize, out byte[] iv); decoder.Key = key; decoder.IV = iv; decoder.Decrypt(str, out string outstr); var outfn = Path.Combine(outdir, afaTool.afaTool.getPathWithoutDir(fl, dir)); if (!Directory.Exists(Path.GetDirectoryName(outfn))) { Directory.CreateDirectory(Path.GetDirectoryName(outfn)); } File.WriteAllText(outfn, outstr); } } }
public void TestRijndaelCrypto() { var crypto = new RijndaelCryptography(); const string originalString = "Rijndael cryptography"; var cryptoString = crypto.Encrypt(originalString); var decryptString = crypto.Decrypt(cryptoString); Assert.AreEqual(originalString, decryptString); }
/// <summary> /// Decrpyt Cookie values /// </summary> /// <param name="cookie">The cookie.</param> /// <returns></returns> private static HttpCookie DecryptCookie(HttpCookie cookie) { HttpCookie _cookie = new HttpCookie(cookie.Name); if (!string.IsNullOrEmpty(cookie.Value)) { _cookie.Value = RijndaelCryptography.Decrypt(cookie.Value, defaultKey); } return(_cookie); }
public static string Decrypt(this string value, string key = null, string vector = null) { var buffer = Convert.FromBase64String(value); var cripto = new RijndaelCryptography(); if (key != null && vector != null) { cripto.Key = ASCIIEncoding.Default.GetBytes(key); cripto.IV = ASCIIEncoding.Default.GetBytes(vector); } var result = cripto.Decrypt(buffer); return(result.TrimSafe('\0')); }
/// <summary> /// Decrypts the token. /// </summary> /// <param name="token">The token.</param> /// <returns></returns> private static string[] DecryptToken(string token) { string unencryptedToken = RijndaelCryptography.Decrypt(token); return(unencryptedToken.Split('|')); }
/// <summary> /// Decrypts the specified encrypted text. /// </summary> /// <param name="encryptedText">The encrypted text.</param> /// <returns></returns> public string Decrypt(string encryptedText) { string decryptText = RijndaelCryptography.Decrypt(encryptedText); return(decryptText); }