1
0
mirror of https://github.com/bitwarden/directory-connector synced 2025-12-16 16:23:41 +00:00

log in and store protected settings

This commit is contained in:
Kyle Spearrin
2017-05-12 10:15:34 -04:00
parent 0e8a5d229a
commit fa743815f8
17 changed files with 1038 additions and 103 deletions

View File

@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Bit.Core.Models
{
public class EncryptedData
{
public EncryptedData() { }
public EncryptedData(byte[] plainValue)
{
IV = RandomBytes();
Value = ProtectedData.Protect(plainValue, IV, DataProtectionScope.CurrentUser);
}
public byte[] Value { get; set; }
public byte[] IV { get; set; }
public byte[] Decrypt()
{
return ProtectedData.Unprotect(Value, IV, DataProtectionScope.CurrentUser);
}
private byte[] RandomBytes()
{
var entropy = new byte[16];
new RNGCryptoServiceProvider().GetBytes(entropy);
return entropy;
}
}
}