public string Decrypt(string encryptedText, string pathToFile) { string jsonString = File.ReadAllText(pathToFile); TwoFishModel model = JsonConvert.DeserializeObject <TwoFishModel>(jsonString); IV = Convert.FromBase64String(model.IV); SetupKey(Convert.FromBase64String(model.Key)); var plainText = Decrypt_CBC(encryptedText); return(plainText); }
public string Encrypt(string text, string pathToFile) { SetupKey(GenerateKey()); string cipherText = Encrypt_CBC(text); if (!string.IsNullOrWhiteSpace(cipherText)) { TwoFishModel model = new TwoFishModel(); model.Key = Convert.ToBase64String(key); model.IV = Convert.ToBase64String(IV); File.WriteAllText(pathToFile + FileName, JsonConvert.SerializeObject(model)); } return(Converter.StringToBinary(cipherText)); }