Example #1
0
        public string GetEncryptCredentialInString()
        {
            var certificate = new CertificateHelper().GetCertificateOfServer();
            var cryptoProvider = new CollectServiceCryptoProvider();

            var encryptCredential =
                cryptoProvider.EncryptCredentialBasedOnCertificateOfServer(this.GetCredential(), certificate);

            return System.Text.Encoding.Default.GetString(encryptCredential);
        }
Example #2
0
        public void Expect_CryptographicException_when_a_invalid_certificate_is_used_to_encrypt_credentials()
        {
            var certificate = new CertificateHelper().GetCertificateOfServerByName("LocalhostCertificate.pfx");
            var cryptoProvider = new CollectServiceCryptoProvider();

            var encryptedCredentials =
                cryptoProvider
                    .EncryptCredentialBasedOnCertificateOfServer(new CredentialFactory().GetCredential(), certificate);

            var plainCredentials =
                cryptoProvider
                    .DecryptCredentialBasedOnCertificateOfServer(encryptedCredentials, certificate);
        }
        public void Should_be_possible_to_use_ServerCertificate_to_do_assimetric_cryptography()
        {
            var certificate = new CertificateHelper().GetCertificateOfServer();
            var cryptoProvider = new CollectServiceCryptoProvider();
            var encryptedCredentials = 
                cryptoProvider
                    .EncryptCredentialBasedOnCertificateOfServer(new CredentialFactory().GetCredential(), certificate);
            var plainCredentials = 
                cryptoProvider
                    .DecryptCredentialBasedOnCertificateOfServer(encryptedCredentials, certificate);

            Assert.IsNotNull(plainCredentials, "The credentials after decryptation cannot be nuul.");
            Assert.AreEqual("fake_domain", plainCredentials.Domain);
            Assert.AreEqual("john_doe", plainCredentials.UserName);
            Assert.AreEqual("******", plainCredentials.Password);
        }