Exemplo n.º 1
0
        public static string cerEncrypt(string md5SignStr, string cerPath)
        {
            string signature = RSAUtil.Base64Encoder(RSAUtil.RSAEncrypt(RSAUtil.getPublicKeyXmlFromCer(cerPath).PublicKey.Key.ToXmlString(false),
                                                                        RSAUtil.getBytesFromString(md5SignStr, Encoding.UTF8)));

            return(signature);
        }
Exemplo n.º 2
0
        public void genEncryptData(string data, string cerPath, string pfxPath, string password, out string encryptData, out string sign, out string encryptKey)
        {
            encryptData = "";
            encryptKey  = "";
            sign        = "";
            try
            {
                // 加载公私钥
                X509Certificate2 publicKeyInfo  = DataCertificate.GetCertFromCerFile(cerPath);
                X509Certificate2 privateKeyInfo = DataCertificate.GetCertificateFromPfxFile(pfxPath, password);

                string platPublicKey = publicKeyInfo.PublicKey.Key.ToXmlString(false);

                string merchantPublicKey  = privateKeyInfo.PublicKey.Key.ToXmlString(false); // 公钥
                string merchantPrivateKey = privateKeyInfo.PrivateKey.ToXmlString(true);     // 私钥

                //byte[] plainBytes = Encoding.UTF8.GetBytes(data);
                //生成AESKEY
                string aesKey = ComUtils.CreateRandomString(16);
                //报文加密
                encryptData = Base64.EncodeBase64(Encoding.UTF8, AESUtil.Encrypt(data, aesKey));
                //生成签名
                sign = Base64.EncodeBase64(Encoding.UTF8, RSAUtil.RSAEncrypt(merchantPrivateKey, data));
                //AESKEY加密
                encryptKey = Base64.EncodeBase64(Encoding.UTF8, AESUtil.Encrypt(data, platPublicKey));
            }
            catch (Exception e)
            {
                log.Write(e, MsgType.Error);
            }
        }