المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Extract private key from sn.exe keyfile



C# Programming
05-24-2009, 05:58 AM
hello

Suppose you have generated a key pair using sn.exe as follows:

sn -k keypair.snk Generates and stores the key pair in the file 'sn1.snk'.
sn -p publickeyonly.snk snpub1.snk Extracts the public key.


Now this is how you can extract public key programmatically.

public static byte[] ExtractPublicKeyFromKeyPairFile(string strKeyPairFile)
{
FileStream oKeyPairFileStream = File.OpenRead(strKeyPairFile);
System.Reflection.StrongNameKeyPair oKeyPairFile = new StrongNameKeyPair(oKeyPairFileStream);
byte[] btPublicKey = oKeyPairFile.PublicKey;
return btPublicKey;
}


Question is, what about private key? "StrongNameKeyPair" don't have a "PrivateKey" accessor.

Thanks

dev