• 大小: 40KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-16
  • 语言: 其他
  • 标签: ECDSA  加密  C#  源码  

资源简介

ECDSA签名是美国联邦的标准,此加密算法利用签名保存公钥和私钥,代码很简单!

资源截图

代码片段和文件信息

/*
 * 功  能:ECDSA签名用于密码技术
 * 
 * 用  法:将数据库脚本复制到sqlserver新建查询里执行,【加密】按钮将输入的密码哈希生成签名存入数据库(包括公钥),
 *       【效验】按钮将公钥以及签名从数据库中取出来,通过用签名效验用户输入的密码哈希值是否正确
 *
 * 时  间:2010/3/29 15:10:30
 *
 * 程序员:王文壮
 *
 * Q    Q:1020304029
 *
 * 邮  箱:WangWenzhuang_net@163.com
 *
 * 博  客:http://blog.csdn.net/wangwenzhuang
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Security.Cryptography;

namespace ECDSAEncryption
{
    public partial class Form1 : Form
    {
        /* 数据库脚本
           USE MASTER
           GO
           IF EXISTS(SELECT * FROM SYSDATAbaseS WHERE NAME=‘TEMP_TEST‘)
           BEGIN
           DROP DATAbase TEMP_TEST
           END
           GO
           CREATE DATAbase TEMP_TEST
           GO
           USE TEMP_TEST
           GO
           IF EXISTS(SELECT * FROM SYSobjectS WHERE NAME=‘TEMP_USER‘)
           BEGIN
           DROP TABLE TEMP_USER 
           END
           GO
           CREATE TABLE TEMP_USER
           (
           PUBLICKEY BINARY(140) NOT NULL --公钥
           SIGNATURE BINARY(132) NOT NULL --签名
           )
         */
        SqlConnection con;

        public Form1()
        {
            InitializeComponent();
            con = new SqlConnection(“Data Source=.;Initial Catalog=TEMP_TEST;Integrated Security=True“);
            con.Open();
        }

        private void buttonEncryption_Click(object sender EventArgs e)
        {
            ///签名
            byte[] sign;
            ///公钥
            byte[] pubKey;
            ///哈希值
            byte[] hash = new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(textBoxPasswordInit.Text));
            ///创建密钥对
            using (CngKey key = CngKey.Create(CngAlgorithm.ECDsaP521))
            {
                ///从密钥对中导出公钥
                pubKey = key.Export(CngKeyBlobFormat.GenericPublicBlob);
                ECDsaCng eCDsaCng = new ECDsaCng(key);
                ///签名
                sign = eCDsaCng.SignHash(hash);
                eCDsaCng.Clear();
            }
            if (Command(“INSERT INTO TEMP_USER(PUBLICKEYSIGNATURE) VALUES(@PUBLICKEY@SIGNATURE)“ new SqlParameter(“@PUBLICKEY“ pubKey) new SqlParameter(“@SIGNATURE“ sign)) > 0)
            {
                MessageBox.Show(“存入数据库!“);
            }
        }

        private void buttonValidation_Click(object sender EventArgs e)
        {
            ///签名
            byte[] sign = null;
            ///公钥
            byte[] pubKey = null;
            ///结果
            bool result;
            ///哈希值
            byte[] hash = new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(textBoxPasswordLast.Text));
            SqlCommand cmd = new SqlCommand(“SELECT PUBLICKEYSIGNATURE FROM TEMP_USER“ con);

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      11776  2010-03-29 15:18  ECDSAEncryption\ECDSAEncryption\bin\Debug\ECDSAEncryption.exe

     文件      26112  2010-03-29 15:18  ECDSAEncryption\ECDSAEncryption\bin\Debug\ECDSAEncryption.pdb

     文件      14328  2010-03-29 14:55  ECDSAEncryption\ECDSAEncryption\bin\Debug\ECDSAEncryption.vshost.exe

     文件        490  2009-06-11 05:14  ECDSAEncryption\ECDSAEncryption\bin\Debug\ECDSAEncryption.vshost.exe.manifest

     文件       3776  2010-03-29 14:24  ECDSAEncryption\ECDSAEncryption\ECDSAEncryption.csproj

     文件       4552  2010-03-29 15:18  ECDSAEncryption\ECDSAEncryption\Form1.cs

     文件       5841  2010-03-29 15:18  ECDSAEncryption\ECDSAEncryption\Form1.Designer.cs

     文件       5814  2010-03-29 15:18  ECDSAEncryption\ECDSAEncryption\Form1.resx

     文件        668  2010-03-29 15:07  ECDSAEncryption\ECDSAEncryption\obj\Debug\ECDSAEncryption.csproj.FileListAbsolute.txt

     文件        847  2010-03-29 15:18  ECDSAEncryption\ECDSAEncryption\obj\Debug\ECDSAEncryption.csproj.GenerateResource.Cache

     文件      11776  2010-03-29 15:18  ECDSAEncryption\ECDSAEncryption\obj\Debug\ECDSAEncryption.exe

     文件        180  2010-03-29 15:18  ECDSAEncryption\ECDSAEncryption\obj\Debug\ECDSAEncryption.Form1.resources

     文件      26112  2010-03-29 15:18  ECDSAEncryption\ECDSAEncryption\obj\Debug\ECDSAEncryption.pdb

     文件        180  2010-03-29 14:24  ECDSAEncryption\ECDSAEncryption\obj\Debug\ECDSAEncryption.Properties.Resources.resources

     文件        496  2010-03-29 14:14  ECDSAEncryption\ECDSAEncryption\Program.cs

     文件       1362  2010-03-29 14:14  ECDSAEncryption\ECDSAEncryption\Properties\AssemblyInfo.cs

     文件       2880  2010-03-29 14:14  ECDSAEncryption\ECDSAEncryption\Properties\Resources.Designer.cs

     文件       5612  2010-03-29 14:14  ECDSAEncryption\ECDSAEncryption\Properties\Resources.resx

     文件       1100  2010-03-29 14:14  ECDSAEncryption\ECDSAEncryption\Properties\Settings.Designer.cs

     文件        249  2010-03-29 14:14  ECDSAEncryption\ECDSAEncryption\Properties\Settings.settings

     文件        935  2010-03-29 14:14  ECDSAEncryption\ECDSAEncryption.sln

    ..A..H.     14848  2010-03-29 15:25  ECDSAEncryption\ECDSAEncryption.suo

     目录          0  2010-03-29 14:16  ECDSAEncryption\ECDSAEncryption\obj\Debug\Refactor

     目录          0  2010-03-29 14:14  ECDSAEncryption\ECDSAEncryption\obj\Debug\TempPE

     目录          0  2010-03-29 14:24  ECDSAEncryption\ECDSAEncryption\bin\Debug

     目录          0  2010-03-29 15:18  ECDSAEncryption\ECDSAEncryption\obj\Debug

     目录          0  2010-03-29 14:14  ECDSAEncryption\ECDSAEncryption\bin

     目录          0  2010-03-29 14:14  ECDSAEncryption\ECDSAEncryption\obj

     目录          0  2010-03-29 14:14  ECDSAEncryption\ECDSAEncryption\Properties

     目录          0  2010-03-29 15:18  ECDSAEncryption\ECDSAEncryption

............此处省略4个文件信息

评论

共有 条评论