protected override ClientConfiguration GetConnectionConfig() { //Define some common key names for associating keys const string publicKeyName = "MyPublicKeyName"; const string privateKeyName = "MyPrivateKeyName"; //Open the X509 cert from the .pfx generated from the steps above var cert = new X509Certificate2("public_privatekey.pfx", "password", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable); //Create the keystore for X509 certs var keyStore = new X509CertificateKeyStore(cert) { PrivateKeyName = privateKeyName, PublicKeyName = publicKeyName }; //Create the RSA crypto provider var cryptoProvider = new RsaCryptoProvider(keyStore) { PrivateKeyName = privateKeyName, PublicKeyName = publicKeyName }; //Get the config and enable field encryption var config = base.GetConnectionConfig(); config.EnableFieldEncryption("MyRSAProvider", cryptoProvider); return(config); }
public void Test_Encrypt() { var rsaCryptoProvider = new RsaCryptoProvider { KeyStore = _keystore, KeyName = "publicKey", PrivateKey = "privateKey" }; var someText = "The old grey goose jumped over the wrickety vase."; var encryptedTest = rsaCryptoProvider.Encrypt(someText); Assert.NotEqual(encryptedTest, someText); }