Exemplo n.º 1
0
        public void TestThat_CanDecryptTaggedForEncryption()
        {
            var key = "fbxgmcR6eyxA1DIDHbFj2H3HNWopsjYL1hhx3DUALAk=";
            string yml = @"SomeKey: Administrator
            SomeSensitiveKey:
            IV: QQm4IgHsOVLyoA0izfzfGw==
            Value: tBkEGpVzcNpommpdPWVa8X9QQJkaTnFSW0Q5yGJicL8=";

            var crypto = new YamlConfigCrypto(key);
            Assert.That(crypto.IsEncrypted(yml));

            var decryptedYml = crypto.Decrypt(yml);
            Assert.That(!crypto.IsEncrypted(decryptedYml));
        }
Exemplo n.º 2
0
        public void TestThat_CanDecryptYaml()
        {
            var key = JsonPasswordCrypto.GenerateKey(256);
            var crypto = new YamlConfigCrypto(key);

            var encryptedYml = crypto.Encrypt(_yml);
            Assert.That(crypto.IsEncrypted(encryptedYml));

            var decryptedYml = crypto.Decrypt(encryptedYml);
            Assert.That(!crypto.IsEncrypted(decryptedYml));
        }
Exemplo n.º 3
0
        public void TestThat_CanDecryptPassword()
        {
            var key = "RYqIgFuJQA5E9LeKRY+F7uJKD7qjs97jcsJ0IYrOAOs=";
            string yml = @"UserName: Administrator
            Password:
            IV: BYmlG/ynplh5JZ3mZTbfaQ==
            Value: QAjlFzJPk1q5+qnqaEybpQ==";

            var crypto = new YamlConfigCrypto(key);
            Assert.That(crypto.IsEncrypted(yml));

            var decryptedYml = crypto.Decrypt(yml);
            Assert.That(!crypto.IsEncrypted(decryptedYml));

            using (var reader = new StringReader(decryptedYml))
            {
                var stream = new YamlStream();
                stream.Load(reader);

                var node = ((YamlMappingNode) stream.Documents[0].RootNode).Children[new YamlScalarNode("Password")] as YamlScalarNode;
                Assert.That(node.Value, Is.EqualTo("SomePassword"));
            }
        }