public static void V_Test_RSA_PublicKeyFromPrivate() { Console.WriteLine("Testing RSA_PublicKeyFromPrivate ..."); string strPriKeyFile = null; StringBuilder sbPrivateKey = null; string strPublicKey = null; int nCode = 0; int nRet = 0; // Read private key from encrypted private key file into internal string form strPriKeyFile = "myuser.epk"; sbPrivateKey = Rsa.ReadEncPrivateKey(strPriKeyFile, "password"); if (sbPrivateKey.Length == 0) { return; } //Catch error here // Display some info about it Console.WriteLine("Private key length = {0} bits", Rsa.KeyBits(sbPrivateKey.ToString())); nCode = Rsa.KeyHashCode(sbPrivateKey.ToString()); Console.WriteLine("KeyHashCode={0,8:X}", nCode); nRet = Rsa.CheckKey(sbPrivateKey); Console.WriteLine("Rsa.CheckKey returns " + nRet + ": (PKI_VALID_PRIVATEKEY=" + 0 + ")"); // Convert to public key string strPublicKey = Rsa.PublicKeyFromPrivate(sbPrivateKey).ToString(); if (strPublicKey.Length == 0) { return; } // Catch error here // Display some info about it Console.WriteLine("Public key length = " + Rsa.KeyBits(strPublicKey) + " bits"); nCode = Rsa.KeyHashCode(strPublicKey); Console.WriteLine("KeyHashCode={0,8:X}", nCode); nRet = Rsa.CheckKey(strPublicKey); Console.WriteLine("Rsa.CheckKey returns " + nRet + ": (PKI_VALID_PUBLICKEY=" + 1 + ")"); // Clean up Wipe.String(sbPrivateKey); }