11.07.2015 Views

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13: Building Secure Remoted Components 363The following steps outline the basic approach to implement a customencryption sink:1. Create a public/private key pair for the solution.const int AT_KEYEXCHANGE = 1;CspParameters cspParams = new CspParameters();cspParams.KeyContainerName = "";cspParams.KeyNumber = AT_KEYEXCHANGE;cspParams.ProviderName = "Microsoft Base Cryptographic Provider v1.0";cspParams.ProviderType = PROV_RSA_FULL;RSACryptoServiceProvider rsaServerSide = newRSACryptoServiceProvider(cspParams);rsaServerSide.PersistKeyInCsp = true;Console.WriteLine(rsaServerSide.ToXmlString(true)); // Writes the public key2. Expose the public key for clients to consume.The client maintains a copy of the public key in a file.3. Initialize the client channel sink <strong>and</strong> create a r<strong>and</strong>om key for encryption.byte[] r<strong>and</strong>omKey = new byte[size];RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();rng.GetBytes(r<strong>and</strong>omKey);4. Encrypt the r<strong>and</strong>om key with the pubic key of your server. UseIClientChannelSink.ProcessMessage to send the encrypted key to the server.RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(csp);rsa.FromXmlString("

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!