Groups | Blog | Home
all groups > dotnet security > july 2006 >

dotnet security : Showing the private key stored in a pfx file



BobNL
7/21/2006 6:09:02 AM
Hi,

I show the public and private key stored in a pfx file. The public key
is the same every time I run the program, but the private key isn't.
Can someone explain to me why the private key isn't the same every time
I run the program?

I show the keyexponent and keymodulus of the public key, and the D
parameter of the private key, with the following C# code:

---------------
PfxOpen pfx = new PfxOpen();
String pfxFilename = @"E:\Prototype\Test\Release2\key.pfx";
String password = "geheim";
if(!pfx.LoadPfx(pfxFilename, ref password))
{
throw new Exception("Failed to load pfx");
}

CspParameters cspParameters = new CspParameters();
cspParameters.Flags = CspProviderFlags.UseMachineKeyStore;
cspParameters.KeyContainerName = pfx.container;
RSACryptoServiceProvider rsaCryptoServiceProvider =
new RSACryptoServiceProvider(cspParameters);
RSAParameters rsaParameters =
rsaCryptoServiceProvider.ExportParameters(true);

MessageBox.Show("container: " + pfx.container
+ "\n\n" + "keyexponent: " + ByteArrayToString(pfx.keyexponent)
+ "\n\n" + "keymodulus: " + ByteArrayToString(pfx.keymodulus)
+ "\n\n" + "D: " + ByteArrayToString(rsaParameters.D)
);
---------------

I'm using PfxOpen.cs and win32.cs from
http://msdn.microsoft.com/library/en-us/dncapi/html/pkcs12.asp and I'm
using .NET framework version 1.1.

Cheers,

Bob
BobNL
7/25/2006 1:55:02 AM
[quoted text, click to view]

Because I found out this isn't an MSDN managed newsgroup I also asked my
question in microsoft.public.dotnet.framework. Please go to that group for an
answer.

Cheers,

AddThis Social Bookmark Button