Esempio n. 1
0
        /// <summary>
        /// 3DES解密
        /// </summary>
        /// <param name="pKey">解密密钥</param>
        /// <param name="pDecryptContent">需要解密的内容</param>
        /// <returns></returns>
        public static byte[] TripleDESDecrypt(string pKey, string pDecryptContent)
        {
            byte[] keyBytes     = Encoding.UTF8.GetBytes(pKey);
            byte[] contentBytes = Encoding.UTF8.GetBytes(pDecryptContent);

            return(EncDecUtil.TripleDESDecrypt(keyBytes, contentBytes));
        }
Esempio n. 2
0
        /// <summary>
        /// 解析请求报文
        /// <remarks>
        /// <para>请求报文是支付前置发给商户平台的,用于通知API</para>
        /// </remarks>
        /// </summary>
        /// <param name="pCertFilePath">cer证书文件路径</param>
        /// <param name="pCertFilePassword">pfx证书文件密码</param>
        /// <param name="pRequestContent">加密后的请求内容</param>
        /// <returns></returns>
        public static string ParseRequestPackets(string pCerFilePath, string pRequestContent)
        {
            //参数检查
            if (string.IsNullOrWhiteSpace(pRequestContent))
            {
                return(null);
            }
            var content = pRequestContent.Replace("\0", string.Empty);

            if (string.IsNullOrWhiteSpace(content))
            {
                return(null);
            }
            //
            string[] sections = content.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            if (sections.Length != 3)
            {
                throw new ArgumentException("格式非法的报文.");
            }
            string merchantID = Encoding.UTF8.GetString(EncDecUtil.Base64Decrypt(sections[0]));

            byte[] encryptedKey = EncDecUtil.Base64Decrypt(sections[1]);
            string desKey       = Encoding.UTF8.GetString(EncDecUtil.RSADecrypt(pCerFilePath, encryptedKey));

            byte[] key              = Encoding.ASCII.GetBytes(desKey.Substring(0, 24));
            byte[] keyIV            = Encoding.ASCII.GetBytes(desKey.Substring(24, 8));
            byte[] encryptedContent = EncDecUtil.Base64Decrypt(sections[2]);
            string decryptedContent = Encoding.UTF8.GetString(EncDecUtil.TripleDESDecrypt(key, encryptedContent));

            //
            return(decryptedContent);
        }