private static void EncryptJsonValue(JsonPasswordCrypto cryptoHandler, JValue valueToEncrypt)
 {
     var value = valueToEncrypt.Value<string>();
     var encryptedValue = cryptoHandler.Encrypt(value);
     valueToEncrypt.Replace(JObject.FromObject(encryptedValue));
 }
 private static void DecryptJsonValue(JsonPasswordCrypto cryptoHandler, dynamic originalValue)
 {
     var valueToDecrypt = new EncryptedValue(originalValue.IV.Value, originalValue.Value.Value);
     var decryptedValue = cryptoHandler.Decrypt(valueToDecrypt);
     JObject valueToReplace = originalValue;
     valueToReplace.Replace(decryptedValue);
 }
 public JsonConfigCrypto(string key)
 {
     _valueHandler = new JsonPasswordCrypto(key);
 }
 private static void EncryptTaggedValue(JsonPasswordCrypto cryptoHandler, dynamic valueToEncrypt)
 {
     var value = valueToEncrypt.encrypt.Value;
     var encryptedValue = cryptoHandler.Encrypt(value);
     valueToEncrypt.Replace(JObject.FromObject(encryptedValue));
 }
        private static void EncryptTaggedValue(JsonPasswordCrypto cryptoHandler, KeyValuePair<YamlMappingNode, YamlNode> containerKeyPair)
        {
            var container = containerKeyPair.Key;
            var key = containerKeyPair.Value;
            var value = container.Children[key].ToString();
            var encryptedValue = cryptoHandler.Encrypt(value);

            container.Children.Remove(key);

            var serializer = new Serializer();

            using (var writer = new StringWriter())
            {
                serializer.Serialize(writer, encryptedValue);

                var stream = new YamlStream();
                stream.Load(new StringReader(writer.ToString()));
                stream.Documents[0].RootNode.Tag = "tag:yaml.org,2002:encrypted";
                container.Add(key, stream.Documents[0].RootNode);
            }
        }
 private static void DecryptYamlValue(JsonPasswordCrypto cryptoHandler, YamlEncryptedNode encryptedNode)
 {
     var decryptedValue = cryptoHandler.Decrypt(encryptedNode.EncryptedValue);
     encryptedNode.Parent.Children.Remove(encryptedNode.Container);
     encryptedNode.Parent.Add(encryptedNode.Container.Key, decryptedValue);
 }