public void Should_be_possible_to_encrypt_credential_based_on_certificate_of_server() { var encryptCredential = new CollectServiceCryptoProvider() .EncryptCredentialBasedOnCertificateOfServer( new CredentialFactory().GetCredential(), new CertificateHelper().GetCertificateOfServer()); Assert.IsNotNull(encryptCredential); }
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_export_the_public_part_of_the_certificate_in_pfx_format() { 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); }
public void Should_be_possible_to_decrypt_credential_based_on_certificate_of_server() { var credential = new CollectServiceCryptoProvider() .DecryptCredentialBasedOnCertificateOfServer( this.EncryptedCredentialInBytes, new CertificateHelper().GetCertificateOfServer()); Assert.IsNotNull(credential); Assert.AreEqual("john_doe", credential.UserName); Assert.AreEqual("******", credential.Password); }
public void If_a_null_credential_was_passed_the_crypto_provider_must_return_a_new_Credential_instance() { var credential = new CollectServiceCryptoProvider() .DecryptCredentialBasedOnCertificateOfServer(null, null); Assert.IsNotNull(credential, "Crypto Provider must return a instance of Credential class."); Assert.IsNull(credential.Domain, "The Domain field must be null."); Assert.IsNull(credential.UserName, "The UserName field must be null."); Assert.IsNull(credential.Password, "The Password field must be null."); Assert.IsNull(credential.AdministrativePassword, "The AdministrativePassword field must be null."); }
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); }
public TargetInfo GetTargetInformation(byte[] credentialInfo, string targetAddress, string PortNum) { var certificate = new CertificateFactory().GetCertificate(); var deserializedCredentials = new CollectServiceCryptoProvider() .DecryptCredentialBasedOnCertificateOfServer(credentialInfo, certificate); return new TargetInfoFactory( targetAddress, deserializedCredentials.Domain, deserializedCredentials.UserName, deserializedCredentials.Password, deserializedCredentials.AdministrativePassword, PortNum).Create(); }
private String EncryptCredentials(Credential credentials) { var certificateInBytes = this.GetCertificate(); var encryptedBytes = new CollectServiceCryptoProvider() .EncryptCredentialBasedOnCertificateOfServer( credentials, new X509Certificate2(certificateInBytes, this.CertificatePassword)); return System.Text.Encoding.Default.GetString(encryptedBytes); }