/// <summary> /// Initializes a new instance of the <see cref="DashboardEncryptor"/> class. /// </summary> public DashboardEncryptor() { this.seed = EncryptionHelper.GetRandomSeed(SeedLength); this.salt = EncryptionHelper.GetRandomSeed(32); this.key = EncryptionHelper.GenerateAesKeyFromSeed(seed, salt); }
/// <summary> /// Initializes a new instance of the <see cref="DashboardDecryptor"/> class. /// </summary> /// <param name="encryptedDashboard">The encrypted dashboard.</param> public DashboardDecryptor(Dashboard encryptedDashboard) { var seed = Convert.FromBase64String(encryptedDashboard.Key); var salt = Convert.FromBase64String(encryptedDashboard.Salt); this.key = EncryptionHelper.GenerateAesKeyFromSeed(seed, salt); }
/// <summary> /// Initializes a new instance of the <see cref="DashboardEncryptor" /> class. /// </summary> /// <param name="dashboard">The dashboard.</param> public DashboardEncryptor(Dashboard dashboard) { this.seed = Convert.FromBase64String(dashboard.Key); this.salt = Convert.FromBase64String(dashboard.Salt); this.key = EncryptionHelper.GenerateAesKeyFromSeed(seed, salt); }
/// <summary> /// Symmetrics the decrypt data. /// </summary> /// <param name="data"> /// The data. /// </param> /// <param name="key"> /// The key. /// </param> /// <returns> /// Decrypted data /// </returns> public static byte[] SymmetricDecryptData(byte[] data, AesKey key) { if (data == null) { throw new ArgumentException(nameof(data)); } if (key == null) { throw new ArgumentNullException(nameof(key)); } using (var algorithm = new AesManaged()) { return Transform(data, algorithm.CreateDecryptor(key.GetKey(), key.GetInitializationVector())); } }
/// <summary> /// Encripts the in base64. /// </summary> /// <param name="content">The content.</param> /// <param name="key">The key.</param> /// <returns></returns> public static string SymmetricEncryptInBase64(string content, AesKey key) { if (key == null) { throw new ArgumentNullException("key"); } return Convert.ToBase64String(SymmetricEncryptData(Encoding.UTF8.GetBytes(content), key)); }
/// <summary> /// Encripts the in base64. /// </summary> /// <param name="content">The content.</param> /// <param name="key">The key.</param> /// <returns></returns> public static string SymmetricDecryptInBase64(string content, AesKey key) { if (string.IsNullOrEmpty(content)) { throw new ArgumentNullException("content"); } if (key == null) { throw new ArgumentNullException("key"); } return Encoding.UTF8.GetString(SymmetricDecryptData(Convert.FromBase64String(content), key)); }