예제 #1
0
        public void RsaSignTest()
        {
            byte[] buffer    = Encoding.UTF8.GetBytes("my name is Jason");
            string pfx       = @"G:\Jason\certs\apiclient_cert.pfx";
            var    rsa       = RsaCertificate.ReadFromPfx(pfx, "1548699391");
            string signature = rsa.SignData(buffer);

            Assert.IsTrue(rsa.VerifyData(buffer, Convert.FromBase64String(signature)));
        }
예제 #2
0
 private void btnReadX509_Click(object sender, EventArgs e)
 {
     try
     {
         string fullpath = Path.Combine(txt_cert_folder.Text.Trim(), txt_cert_name.Text.Trim());
         IRsa   rsa;
         if (fullpath.ToLower().EndsWith(".pfx"))
         {
             rsa = RsaCertificate.ReadFromPfx(fullpath, txt_cert_pwd.Text.Trim());
         }
         else
         {
             rsa = RsaCertificate.ReadFromCert(fullpath);
         }
         txt_private_key.Text = rsa.HasPrivateKey ? rsa.PrivateKey : "";
         txt_public_key.Text  = rsa.PublicKey;
         DisplayKeyPair();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }