private static string GenPassword(string email, string password) { string[] splitEmails = email.Trim().Split('@'); string id = splitEmails.Length == 0 ? string.Empty : splitEmails[0]; byte[] encrypt = AESUtility.AES_Encrypt(Encoding.UTF8.GetBytes(id + password + email.Length.ToString()), Encoding.UTF8.GetBytes(email + password.Length.ToString())); return(Convert.ToBase64String(encrypt)); }
public static string GetDecryptedString(string value, string password) { if (string.IsNullOrEmpty(value)) { return(string.Empty); } try { return(AESUtility.Decrypt(value, password)); } catch (Exception) { return(string.Empty); } }
public static bool LoadFromFile <T>(this T item, string filePath, bool isEncrypted = false, string password = "") where T : IFileSerializable, IJSONSerializable { if (File.Exists(filePath) == false) { return(false); } string jsonText = File.ReadAllText(filePath); if (isEncrypted) { jsonText = AESUtility.Decrypt(jsonText, password); } var jToken = JToken.Parse(jsonText); return(item.FromJSON(jToken)); }
public static bool SaveToFile <T>(this T item, string filePath, bool isEncrypt = false, string password = "") where T : IFileSerializable, IJSONSerializable { Utility.CreateDirectory(filePath); var jToken = item.ToJSON(); if (jToken == null) { return(false); } string jsonText = jToken.ToString(Newtonsoft.Json.Formatting.Indented); if (isEncrypt) { jsonText = AESUtility.Encrypt(jsonText, password); } File.WriteAllText(filePath, jsonText); return(true); }