首页 新闻 会员 周边 捐助

DSACryptoServiceProvider加密和解密问题?请高手帮助完成以下程序

0
悬赏园豆:20 [已关闭问题]

  public class DASymmetrihelper
    {
        private string _signData;
        private string _priateKey;
        private string _publicKey;
        public string SignData
        {
            get
            {
                return _signData;
            }
            set
            {
                this._signData = value;
            }
        }
        public string PublicKey
        {
            get
            {
                return this._publicKey;
            }
            set { this._publicKey = value; }
        }
        public string PrivateKey
        {
            get
            {
                return this._priateKey;
            }
        }
        /// <summary>
        /// 产生私钥和公钥
        /// </summary>
        /// <param name="xmlKeys">私钥</param>
        /// <param name="xmlPublicKey">公钥</param>
        private void GenerateKey(DSACryptoServiceProvider dsa)
        {
            this._priateKey = dsa.ToXmlString(true);
            this._publicKey = dsa.ToXmlString(false);
        }
       
        public string  DSADecrypt(string dencryptString)
        {
            DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(); 
            dsa.FromXmlString(this.PublicKey);
            byte[] fileHashValue = new SHA1CryptoServiceProvider().ComputeHash(Convert.FromBase64String(dencryptString));//产生散列
            string[] splitstr = this.SignData.Split('-');
            byte[] signedHash = new byte[splitstr.Length];
            for (int i = 0; i < signedHash.Length; i++)
                signedHash[i] = byte.Parse(splitstr[i], System.Globalization.NumberStyles.AllowHexSpecifier);
      
            bool flage = dsa.VerifySignature(fileHashValue, signedHash);
            if (flage)
            {
                return "解密后数据";//如何实现
            }
            return false;
        }

        public string DSAEncrypt(string encryptstring)
        {         
            DSACryptoServiceProvider dsa = new DSACryptoServiceProvider();
            GenerateKey(dsa);//产生私钥和公钥
            byte[] source = System.Text.UTF8Encoding.UTF8.GetBytes(encryptstring);
            byte[] fileHashValue = new SHA1CryptoServiceProvider().ComputeHash(source);//产生散列          
            this._signData = BitConverter.ToString(dsa.SignData(fileHashValue)); //生成摘要[数字签名]
             dsa.FromXmlString(this.PrivateKey);//私钥对消息摘要加密
             return "都返回那些值?,如何对消息进行加密?";//怎么返回值呀
        }
    }

幽境仼孓的主页 幽境仼孓 | 初学一级 | 园豆:0
提问于:2009-12-13 13:34
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册