Пример #1
0
 private static void EncryptJsonValue(JsonPasswordCrypto cryptoHandler, JValue valueToEncrypt)
 {
     var value = valueToEncrypt.Value<string>();
     var encryptedValue = cryptoHandler.Encrypt(value);
     valueToEncrypt.Replace(JObject.FromObject(encryptedValue));
 }
Пример #2
0
 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);
 }
Пример #3
0
 public JsonConfigCrypto(string key)
 {
     _valueHandler = new JsonPasswordCrypto(key);
 }
Пример #4
0
 private static void EncryptTaggedValue(JsonPasswordCrypto cryptoHandler, dynamic valueToEncrypt)
 {
     var value = valueToEncrypt.encrypt.Value;
     var encryptedValue = cryptoHandler.Encrypt(value);
     valueToEncrypt.Replace(JObject.FromObject(encryptedValue));
 }
Пример #5
0
        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);
            }
        }
Пример #6
0
 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);
 }