/// <summary> /// Encrypts the data. /// </summary> /// <param name="clearBytes">The clear bytes</param> /// <param name="password">The password bytes</param> /// <param name="iterations">The iterations of the algorithm</param> /// <returns></returns> public static byte[] EncryptAes(byte[] clearBytes, EncryptedString password, int iterations = 1) { var pdb = new Rfc2898DeriveBytes(password.GetBytes(), Salt, iterations); var encryptedData = EncryptAes(clearBytes, pdb.GetBytes(32), pdb.GetBytes(16)); return(encryptedData); }
/// <summary> /// Decrypts the string. /// </summary> /// <param name="encryptedText">The encrypted text.</param> /// <param name="password">The password.</param> /// <param name="iterations">The iterations of the algorithm</param> /// <returns></returns> public static string DecryptAes(string encryptedText, EncryptedString password, int iterations = 1) { var encryptedBytes = Convert.FromBase64String(encryptedText); var clearPassword = password.GetBytes(); var clearBytes = DecryptAes(encryptedBytes, clearPassword, iterations); return(Encoding.Unicode.GetString(clearBytes)); }
/// <summary> /// Encrypts the string. /// </summary> /// <param name="clearText">The clear text.</param> /// <param name="password">The password.</param> /// <param name="iterations">The iterations of the algorithm</param> /// <returns></returns> public static string EncryptAes(string clearText, EncryptedString password, int iterations = 1) { var clearBytes = Encoding.Unicode.GetBytes(clearText); var clearPassword = password.GetBytes(); var encryptedBytes = EncryptAes(clearBytes, clearPassword, iterations); return(Convert.ToBase64String(encryptedBytes)); }
/// <inheritdoc /> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (!(value is string stringValue)) { throw new ArgumentNullException(nameof(value)); } return(EncryptedString.FromEncryptedString(stringValue)); }