예제 #1
0
        public bool Upgrade(SecretsManager sman, Vault vault, string password)
        {
            // Convert JSON strings and byte arrays to plain values

            foreach (var key in new List <string>(sman.Keys))
            {
                sman.DefaultSerializer = new Utf8JsonSerializer();
                sman.TryGetValue(key, out byte[] bytes);

                try
                {
                    var s = Encoding.UTF8.GetString(bytes);
                    var o = JsonConvert.DeserializeObject(s);

                    if (o is string stringValue)
                    {
                        sman.Set(key, stringValue);
                    }
                    else if (o is byte[] byteValue)
                    {
                        sman.Set(key, byteValue);
                    }
                }
                catch
                {
                    throw new VaultVersionException($"Cannot upgrade secret {key}");
                }
            }

            sman.CreateSentinel();

            return(true);
        }
예제 #2
0
 public void Decrypt(string key)
 {
     if (!_sman.TryGetValue(key, out string retrieved))
     {
         throw new ExitCodeException(1, $"Key \"{key}\" not found in secrets store!");
     }
     else
     {
         Console.WriteLine(retrieved);
     }
 }