X509Certificate hell!
From: Sebastien Garrioch via .NET 247 (anonymous_at_dotnet247.com)
Date: 08/04/04
- Next message: Gopalakrishnan N.T via .NET 247: "StrongNameIdentityPermission and Remoting problem"
- Previous message: nayle uzunova via .NET 247: "nayle"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Wed, 04 Aug 2004 05:29:34 -0700
Hi,
I am trying to secure connections to our SQL cluster and want ot use an encrypted connection string. I have issued a certificate from my test CA (Microsoft CA) to my test web server. It's a standard server authentication certificate that can be used for SSL. I have installed WSE 2.0.
Goal:
Use a digital certiicate from my local machine store to encrypt/decrypt the connection string. Once the data is encrypted, a hash must be generated and signed.
Method:
1. Encrypt the connection string and store this in the Windows registry in a binary value using the certificate public key.
Code:
NB: All vars are byte[] if not declared
X509Certificate cert = // Cert x from store
RSAParameters lockConn = cert.Key.ExportParameters(false);
// Prepare to encrypt the connection string.
// Instantiate the cryptographic service provider (RSA).
RSACryptoServiceProvider csp = new RSACryptoServiceProvider();
// Set the algorhythm parameters, encryption key, length, etc.
// lockConn recieved these parameters above.
csp.ImportParameters(lockConn);
// Convert the connection string to an array of bytes.
// Convert from standard ASCII characters to their corresponding bytes.
clearConn = ASCIIEncoding.ASCII.GetBytes("SQL Connection String");
// Encrypt the SQL connection string
cipherConn = csp.Encrypt(clearConn, false);
// Code to write to reg which works just fine...
2. Generate a SHA1 hash of the cipher
Code:
SHA1Managed sm = new SHA1Managed();
hash = sm.ComputeHash(cipherConn);
3. Sign the hash (it dies here with an OID unknown exception)
Code:
RSAPKCS1SignatureFormatter sf = new RSAPKCS1SignatureFormatter(cert.Key);
sf.SetHashAlgorithm("SHA1");
signature = sf.CreateSignature(cipherConn);
I have searched everywhere and can't figure out why it dies. Also when I try to reverse the encryption using the private key it dies. I am really pulling my hair out with this one, can anyone help?
Thanks,
Seb
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>lKBBa8tjFUSsdXaM2dwW1A==</Id>
- Next message: Gopalakrishnan N.T via .NET 247: "StrongNameIdentityPermission and Remoting problem"
- Previous message: nayle uzunova via .NET 247: "nayle"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|