Esempio n. 1
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"));
            }
        }
Esempio n. 2
0
        public void TestThat_CanEncryptYaml()
        {
            var key    = JsonPasswordCrypto.GenerateKey(256);
            var crypto = new YamlConfigCrypto(key);

            var encryptedYml = crypto.Encrypt(_yml);

            Assert.That(crypto.IsEncrypted(encryptedYml));
        }
Esempio n. 3
0
        public void TestThat_CanEncryptTaggedForEncryption()
        {
            string yml = @"SomeKey : Administrator
SomeSensitiveKey : !!encrypt SomeSensitiveValue";

            var key    = JsonPasswordCrypto.GenerateKey(256);
            var crypto = new YamlConfigCrypto(key);

            var encryptedYml = crypto.Encrypt(yml);

            Assert.That(crypto.IsEncrypted(encryptedYml));
        }
Esempio n. 4
0
        public void TestThat_CanEncryptPassword()
        {
            string yml = @"UserName : Administrator
Password : !!encrypt SomePassword";

            var key    = JsonPasswordCrypto.GenerateKey(256);
            var crypto = new YamlConfigCrypto(key);

            var encryptedYml = crypto.Encrypt(yml);

            Assert.That(crypto.IsEncrypted(encryptedYml));
        }
Esempio n. 5
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));
        }