static RSA GetKeyFromFile (string filename)
{
byte[] data = ReadFromFile (filename);
try {
// for SNK files (including the ECMA pseudo-key)
return new StrongName (data).RSA;
}
catch {
if (data.Length == 0 || data [0] != 0x30)
throw;
// this could be a PFX file
Console.Write ("Enter password for private key (will be visible when typed): ");
PKCS12 pfx = new PKCS12 (data, Console.ReadLine ());
// works only if a single key is present
if (pfx.Keys.Count != 1)
throw;
RSA rsa = (pfx.Keys [0] as RSA);
if (rsa == null)
throw;
return rsa;
}
}
#if false