Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="options">微信配置</param>
        public SecurityHelper(WeChatGenOptions options)
        {
            Options = options;

            if (!string.IsNullOrWhiteSpace(Options.WeChatBaseOptions.CertFilePath))
            {
                PrivateCert = new X509Certificate2(Options.WeChatBaseOptions.CertFilePath, Options.WeChatBaseOptions.CertPassword, X509KeyStorageFlags.Exportable);

                PrivateKey = (RSACryptoServiceProvider)PrivateCert.PrivateKey;

                //需要重新导入参数
                var parameters = PrivateKey.ExportParameters(true);

                PrivateKey.ImportParameters(parameters);
            }

            if (!string.IsNullOrWhiteSpace(Options.WeChatBaseOptions.PemFilePath))
            {
                var publicKey = File.ReadAllBytes(Options.WeChatBaseOptions.PemFilePath);
                PublicKey = (RSACryptoServiceProvider)(new X509Certificate2(publicKey).PublicKey.Key);
            }
        }