public DevelopKeyValueStore(string keyFolder) { InternalUtils.EnsureDirectory(keyFolder); var keyName = Path.Combine(keyFolder, DeveloperKeyName); if (!File.Exists(keyName)) { using var key = EncryptionKey.CreateDefault(); File.WriteAllBytes(keyName, key.Serialize()); } _key = EncryptionKey.CreateFromSerializedVersion(File.ReadAllBytes(keyName)); }
public FolderBasedKeyValueStore( string keyMaterialFolderStore, string password) { InternalUtils.EnsureDirectory(keyMaterialFolderStore); var keyName = Path.Combine(keyMaterialFolderStore, "1.key"); if (!File.Exists(keyName)) { //create the first key _key = EncryptionKey.CreateDefault(); var serializedKey = _key.Serialize(); var encryptedSerializedKey = StaticEncryptor.AesEncryptWithPasswordAsync(serializedKey, password).Result; File.WriteAllBytes(keyName, encryptedSerializedKey); } else { var encryptedSerializedKey = File.ReadAllBytes(keyName); var serializedKey = StaticEncryptor.AesDecryptWithPasswordAsync(encryptedSerializedKey, password).Result; _key = EncryptionKey.CreateFromSerializedVersion(serializedKey); } }