예제 #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);
        }
        public void Should_be_possible_to_encrypt_credential_based_on_public_part_of_certificate_of_server()
        {
            var certificateInBytes = new CertificateHelper().GetCertificateOfServer().Export(X509ContentType.Cert);
            var otherCertificate = new X509Certificate2(certificateInBytes);
            Assert.IsNotNull(otherCertificate);

            var credentialInBytes = 
                new CollectServiceCryptoProvider()
                    .EncryptCredentialBasedOnCertificateOfServer(new CredentialFactory().GetCredential(), otherCertificate);
            Assert.IsNotNull(credentialInBytes);
        }
예제 #3
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);
        }
예제 #4
0
        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);
        }
 private X509Certificate2 CreateCertificateWithNoPrivateKey()
 {
     var certificateInBytes = new CertificateHelper().GetCertificateOfServer().Export(X509ContentType.Cert);
     var certificate = new X509Certificate2(certificateInBytes);
     certificate.PrivateKey = null;
     return certificate;
 }