Exemplo n.º 1
0
        /// <summary>
        /// 加密要发送的数据,包含签名,DES加密,RSA加密DES密钥等步骤
        /// </summary>
        /// <param name="data">要加密的正文明文数据</param>
        /// <returns>已加密待发送的密文</returns>
        public string EncryptData(string data)
        {
            data.CheckNotNull("data");

            //获取正文摘要
            string signData = RsaHelper.SignData(data, _hashType, _ownPrivateKey);

            data = new[] { data, signData }.ExpandAndToString(Separator);
            //使用DES加密 正文+摘要
            DesHelper des = new DesHelper();

            data = des.Encrypt(data);
            //RSA加密DES密钥
            string enDesKey = Convert.ToBase64String(RsaHelper.Encrypt(des.Key, _facePublicKey));

            return(new[] { enDesKey, data }.ExpandAndToString(Separator));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 加密要发送的数据,包含签名,AES加密,RSA加密AES密钥等步骤
        /// </summary>
        /// <param name="data">要加密的正文明文数据</param>
        /// <returns>已加密待发送的密文</returns>
        public string EncryptData(string data)
        {
            data.CheckNotNull("data");

            //获取正文摘要
            string signData = RsaHelper.SignData(data, _ownPrivateKey);

            data = new[] { data, signData }.ExpandAndToString(Separator);
            //使用AES加密 正文+摘要
            AesHelper aes = new AesHelper(true);

            data = aes.Encrypt(data);
            //RSA加密AES密钥
            byte[] keyBytes = aes.Key.ToBytes();
            string enDesKey = Convert.ToBase64String(RsaHelper.Encrypt(keyBytes, _facePublicKey));

            return(new[] { enDesKey, data }.ExpandAndToString(Separator));
        }