public void GenerateKeyPairTest() { Tuple <string, string> keyPair = Sm2Utils.CreateKeyPair(); Console.WriteLine("公钥是:{0}", keyPair.Item1); Console.WriteLine("密钥是:{0}", keyPair.Item2); }
public void EncryptTest() { string publicKey = "03b2b5c034deec0efdb3d7c195d5c1bed560fe9b30bd49bb5a7d3dd04ab1987d55"; string cipherText = Sm2Utils.Encrypt(publicKey, "test"); Assert.IsNotNull(cipherText); Console.WriteLine(cipherText); }
public void DecryptTest() { string privateKey = "00ce393e0cf8d8b60196f8b7efc50122b70d341e5f26875317ae2a5add37e9d711"; string cipherText = "04ed3ee3733ddde2c3c0bbf12316df287a6d53ce3000863efded725f54abf3b2fb1f65446104a385450e962b49624f82b477a17bffec8cf2fa4a35d4d87f77c6c290160b0b52b27aa89a1a6bdb14aeedd91a8de66a0b292d3b1ecd2129daa9d368c662363e"; string plainText = Sm2Utils.Decrypt(privateKey, cipherText); Assert.IsNotNull(plainText); Assert.AreEqual("test", plainText); }
//public DigitalValidateContainer(X509Certificate certificate) //{ // _pk = certificate(); //} public override void Validate(SigType type, string signAlgName, byte[] tbsContent, byte[] signedValue) { if (type != SigType.Sign) { throw new ArgumentOutOfRangeException(nameof(type), "签名类型(type)必须是 Sign,不支持电子印章验证"); } Sm2Utils.Verify("", Hex.ToHexString(tbsContent), Hex.ToHexString(signedValue)); //Signature sg = Signature.getInstance(alg, new BouncyCastleProvider()); //sg.initVerify(pk); //sg.update(tbsContent); //if (!sg.verify(signedValue)) //{ // throw new InvalidSignedValueException("签名值不一致"); //} }