mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-04-05 17:37:54 +08:00
docs: 完善文档
This commit is contained in:
parent
7dc4f620c2
commit
548cbf44ec
@ -6,6 +6,8 @@
|
||||
|
||||
同样的,你既然可以利用本库提供的 `RSAUtility` 工具类自行进行签名验证,也可以通过 `CertificateManager` 尝试自动完成签名验证:
|
||||
|
||||
注意,有关 `CertificateManager` 的具体用法,请务必阅读上方给出的相关文档。
|
||||
|
||||
```csharp
|
||||
bool ret = client.VerifyEventSignature(
|
||||
callbackTimestamp: "微信回调通知中的 Wechatpay-Timestamp 字段",
|
||||
|
@ -60,6 +60,8 @@ var client = new WechatTenpayClient(options);
|
||||
你应在后台周期性地调用 `QueryCertificatesAsync()` 方法,并在解密得到证书内容后,记录到证书管理器中:
|
||||
|
||||
```csharp
|
||||
/* 注意:QueryCertificatesAsync() 接口返回值需解密后再存入 */
|
||||
/* 强调:存入的证书式请参考上一小节给出的 CER 证书文件示例 */
|
||||
certManager.SetCertificate("CER 证书序列号", "CER 证书内容");
|
||||
```
|
||||
|
||||
|
@ -1,26 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Utilities
|
||||
{
|
||||
public static class AESUtility
|
||||
{
|
||||
/// <summary>
|
||||
/// 解密数据。
|
||||
/// </summary>
|
||||
/// <param name="keyBytes">AES 密钥字节数组。</param>
|
||||
/// <param name="ivBytes">加密使用的初始化向量字节数组。</param>
|
||||
/// <param name="cipherBytes">待解密数据字节数组。</param>
|
||||
/// <returns>解密后的数据字节数组。</returns>
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Utilities
|
||||
{
|
||||
public static class AESUtility
|
||||
{
|
||||
/// <summary>
|
||||
/// 解密数据。
|
||||
/// </summary>
|
||||
/// <param name="keyBytes">AES 密钥字节数组。</param>
|
||||
/// <param name="ivBytes">加密使用的初始化向量字节数组。</param>
|
||||
/// <param name="cipherBytes">待解密数据字节数组。</param>
|
||||
/// <returns>解密后的数据字节数组。</returns>
|
||||
public static byte[] Decrypt(byte[] keyBytes, byte[] ivBytes, byte[] cipherBytes)
|
||||
{
|
||||
if (keyBytes == null) throw new ArgumentNullException(nameof(keyBytes));
|
||||
if (ivBytes == null) throw new ArgumentNullException(nameof(ivBytes));
|
||||
{
|
||||
if (keyBytes == null) throw new ArgumentNullException(nameof(keyBytes));
|
||||
if (ivBytes == null) throw new ArgumentNullException(nameof(ivBytes));
|
||||
if (cipherBytes == null) throw new ArgumentNullException(nameof(cipherBytes));
|
||||
|
||||
using (SymmetricAlgorithm aes = Aes.Create())
|
||||
@ -35,27 +35,27 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.Utilities
|
||||
cs.Read(plainBytes, 0, plainBytes.Length);
|
||||
return plainBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解密数据。
|
||||
/// </summary>
|
||||
/// <param name="encodingKey">经 Base64 编码后的 AES 密钥。</param>
|
||||
/// <param name="encodingIV">经 Base64 编码后的 AES 初始化向量。</param>
|
||||
/// <param name="encodingCipherText">经 Base64 编码后的待解密数据。</param>
|
||||
/// <returns>解密后的文本数据。</returns>
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解密数据。
|
||||
/// </summary>
|
||||
/// <param name="encodingKey">经 Base64 编码后的 AES 密钥。</param>
|
||||
/// <param name="encodingIV">经 Base64 编码后的 AES 初始化向量。</param>
|
||||
/// <param name="encodingCipherText">经 Base64 编码后的待解密数据。</param>
|
||||
/// <returns>解密后的文本数据。</returns>
|
||||
public static string Decrypt(string encodingKey, string encodingIV, string encodingCipherText)
|
||||
{
|
||||
if (encodingKey == null) throw new ArgumentNullException(nameof(encodingKey));
|
||||
{
|
||||
if (encodingKey == null) throw new ArgumentNullException(nameof(encodingKey));
|
||||
if (encodingCipherText == null) throw new ArgumentNullException(nameof(encodingCipherText));
|
||||
|
||||
byte[] plainBytes = Decrypt(
|
||||
keyBytes: Convert.FromBase64String(encodingKey),
|
||||
ivBytes: Convert.FromBase64String(encodingIV),
|
||||
cipherBytes: Convert.FromBase64String(encodingCipherText)
|
||||
);
|
||||
return Encoding.UTF8.GetString(plainBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
byte[] plainBytes = Decrypt(
|
||||
keyBytes: Convert.FromBase64String(encodingKey),
|
||||
ivBytes: Convert.FromBase64String(encodingIV),
|
||||
cipherBytes: Convert.FromBase64String(encodingCipherText)
|
||||
);
|
||||
return Encoding.UTF8.GetString(plainBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user