public static void TestSm2GetKeyPair() { SM2Utils sm2Utils = new SM2Utils(); ECPoint pubk; BigInteger prik; SM2Utils.GenerateKeyPair(out pubk, out prik); PubKey = Encoding.ASCII.GetString(Hex.Encode(pubk.GetEncoded())).ToUpper(); PriKey = Encoding.ASCII.GetString(Hex.Encode(prik.ToByteArray())).ToUpper(); //System.Console.Out.WriteLine("公钥: " + Encoding.ASCII.GetString(Hex.Encode(publicKey.GetEncoded())).ToUpper()); //System.Console.Out.WriteLine("私钥: " + Encoding.ASCII.GetString(Hex.Encode(privateKey.ToByteArray())).ToUpper()); }
private void BtnSm2Test(object sender, RoutedEventArgs e) { //公钥 string publickey = ""; //私钥 string privatekey = ""; //生成公钥和私钥 SM2Utils.GenerateKeyPair(out publickey, out privatekey); System.Console.Out.WriteLine("加密明文: " + "000000"); System.Console.Out.WriteLine("publickey:" + publickey); //开始加密 string cipherText = SM2Utils.Encrypt(publickey, "000000"); System.Console.Out.WriteLine("密文: " + cipherText); System.Console.Out.WriteLine("privatekey:" + privatekey); //解密 string plainText = SM2Utils.Decrypt(privatekey, cipherText); System.Console.Out.WriteLine("明文: " + plainText); Console.ReadLine(); }