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); } } }
/// <summary> /// Validates client agains PTF database /// </summary> /// <param name="key"></param> /// <param name="countryId"></param> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="encryptedPassword"></param> /// <returns></returns> public static bool ValidateUser(DataPair <string, string> key, int countryId, string userName, string password, ref string encryptedPassword) { List <DbPasswordInfo> psw = MSSQL.ExecuteReader <DbPasswordInfo>(ConnectionStringPft, CommandType.StoredProcedure, "GetUserLoginDetail", new SqlParameter("@CountryId", countryId), new SqlParameter("@UserName", userName) ); if (psw.Count == 0) { return(false); } if (string.IsNullOrEmpty(psw[0].Salt)) { return(psw[0].EncryptedPassword == password); } else { RijndaelCryptography rc = new RijndaelCryptography(); rc.Key = Encoding.ASCII.GetBytes(key.Key); rc.IV = Encoding.ASCII.GetBytes(key.Value); rc.Encrypt(password + psw[0].Salt); encryptedPassword = HttpUtility.UrlEncode(Convert.ToBase64String(rc.Encrypted)); return(psw[0].EncryptedPassword == encryptedPassword); } }
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> /// Encode Cookie values /// </summary> /// <param name="encryptCookie">The encrypt cookie.</param> /// <returns></returns> private static HttpCookie EncryptCookie(HttpCookie encryptCookie) { HttpCookie cookie = new HttpCookie(encryptCookie.Name) { Value = RijndaelCryptography.Encrypt(encryptCookie.Value, defaultKey), Domain = string.Format(".{0}", HttpContext.Current.Request.Url.Host) }; return(cookie); }
/// <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> /// Generates the user token. /// </summary> /// <param name="serviceKey">The service key.</param> /// <returns></returns> public string GenerateUserToken(Guid serviceKey) { bool isValidUser = IsValidUser(serviceKey); string encryptedToken = string.Empty; if (isValidUser) { //Add 5 hours to the current UTC DateTime time = DateTime.UtcNow.AddHours(5); //concate and encrypt the datetime and service key string unencryptedToken = time.Ticks + "|" + serviceKey; encryptedToken = RijndaelCryptography.Encrypt(unencryptedToken); } return(encryptedToken); }
/// <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 hex encoded. /// </summary> /// <param name="hexEncodedText">The hex encoded text.</param> /// <returns>clear Text</returns> public string DecryptHexEncoded(string hexEncodedText) { return(RijndaelCryptography.DecryptHexEncoded(hexEncodedText)); }
/// <summary> /// Encrypts the hex encoded. /// </summary> /// <param name="clearText">The clear text.</param> /// <returns>Hex encoded String</returns> public string EncryptHexEncoded(string clearText) { return(RijndaelCryptography.EncryptHexEncoded(clearText)); }
/// <summary> /// Raws the encrypt. /// </summary> /// <param name="text">The text.</param> /// <returns></returns> public byte[] RawEncrypt(string text) { return(RijndaelCryptography.RawEncrypt(text)); }
/// <summary> /// Raws the decrypt. /// </summary> /// <param name="text">The text.</param> /// <returns></returns> public string RawDecrypt(byte[] text) { return(RijndaelCryptography.RawDecrypt(text)); }
/// <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); }
/// <summary> /// Encrypts the specified plain text. /// </summary> /// <param name="plainText">The plain text.</param> /// <returns></returns> public string Encrypt(string plainText) { string encryptText = RijndaelCryptography.Encrypt(plainText); return(encryptText); }