docs: 完善文档

This commit is contained in:
Fu Diwei
2021-09-18 12:08:45 +08:00
parent 7dc4f620c2
commit 548cbf44ec
3 changed files with 47 additions and 43 deletions

View File

@@ -6,6 +6,8 @@
同样的,你既然可以利用本库提供的 `RSAUtility` 工具类自行进行签名验证,也可以通过 `CertificateManager` 尝试自动完成签名验证: 同样的,你既然可以利用本库提供的 `RSAUtility` 工具类自行进行签名验证,也可以通过 `CertificateManager` 尝试自动完成签名验证:
注意,有关 `CertificateManager` 的具体用法,请务必阅读上方给出的相关文档。
```csharp ```csharp
bool ret = client.VerifyEventSignature( bool ret = client.VerifyEventSignature(
callbackTimestamp: "微信回调通知中的 Wechatpay-Timestamp 字段", callbackTimestamp: "微信回调通知中的 Wechatpay-Timestamp 字段",

View File

@@ -60,6 +60,8 @@ var client = new WechatTenpayClient(options);
你应在后台周期性地调用 `QueryCertificatesAsync()` 方法,并在解密得到证书内容后,记录到证书管理器中: 你应在后台周期性地调用 `QueryCertificatesAsync()` 方法,并在解密得到证书内容后,记录到证书管理器中:
```csharp ```csharp
/* 注意QueryCertificatesAsync() 接口返回值需解密后再存入 */
/* 强调:存入的证书式请参考上一小节给出的 CER 证书文件示例 */
certManager.SetCertificate("CER 证书序列号", "CER 证书内容"); certManager.SetCertificate("CER 证书序列号", "CER 证书内容");
``` ```

View File

@@ -1,26 +1,26 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Security; using System.Security;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
namespace SKIT.FlurlHttpClient.Wechat.Api.Utilities namespace SKIT.FlurlHttpClient.Wechat.Api.Utilities
{ {
public static class AESUtility public static class AESUtility
{ {
/// <summary> /// <summary>
/// 解密数据。 /// 解密数据。
/// </summary> /// </summary>
/// <param name="keyBytes">AES 密钥字节数组。</param> /// <param name="keyBytes">AES 密钥字节数组。</param>
/// <param name="ivBytes">加密使用的初始化向量字节数组。</param> /// <param name="ivBytes">加密使用的初始化向量字节数组。</param>
/// <param name="cipherBytes">待解密数据字节数组。</param> /// <param name="cipherBytes">待解密数据字节数组。</param>
/// <returns>解密后的数据字节数组。</returns> /// <returns>解密后的数据字节数组。</returns>
public static byte[] Decrypt(byte[] keyBytes, byte[] ivBytes, byte[] cipherBytes) public static byte[] Decrypt(byte[] keyBytes, byte[] ivBytes, byte[] cipherBytes)
{ {
if (keyBytes == null) throw new ArgumentNullException(nameof(keyBytes)); if (keyBytes == null) throw new ArgumentNullException(nameof(keyBytes));
if (ivBytes == null) throw new ArgumentNullException(nameof(ivBytes)); if (ivBytes == null) throw new ArgumentNullException(nameof(ivBytes));
if (cipherBytes == null) throw new ArgumentNullException(nameof(cipherBytes)); if (cipherBytes == null) throw new ArgumentNullException(nameof(cipherBytes));
using (SymmetricAlgorithm aes = Aes.Create()) using (SymmetricAlgorithm aes = Aes.Create())
@@ -35,27 +35,27 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.Utilities
cs.Read(plainBytes, 0, plainBytes.Length); cs.Read(plainBytes, 0, plainBytes.Length);
return plainBytes; return plainBytes;
} }
} }
} }
/// <summary> /// <summary>
/// 解密数据。 /// 解密数据。
/// </summary> /// </summary>
/// <param name="encodingKey">经 Base64 编码后的 AES 密钥。</param> /// <param name="encodingKey">经 Base64 编码后的 AES 密钥。</param>
/// <param name="encodingIV">经 Base64 编码后的 AES 初始化向量。</param> /// <param name="encodingIV">经 Base64 编码后的 AES 初始化向量。</param>
/// <param name="encodingCipherText">经 Base64 编码后的待解密数据。</param> /// <param name="encodingCipherText">经 Base64 编码后的待解密数据。</param>
/// <returns>解密后的文本数据。</returns> /// <returns>解密后的文本数据。</returns>
public static string Decrypt(string encodingKey, string encodingIV, string encodingCipherText) 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)); if (encodingCipherText == null) throw new ArgumentNullException(nameof(encodingCipherText));
byte[] plainBytes = Decrypt( byte[] plainBytes = Decrypt(
keyBytes: Convert.FromBase64String(encodingKey), keyBytes: Convert.FromBase64String(encodingKey),
ivBytes: Convert.FromBase64String(encodingIV), ivBytes: Convert.FromBase64String(encodingIV),
cipherBytes: Convert.FromBase64String(encodingCipherText) cipherBytes: Convert.FromBase64String(encodingCipherText)
); );
return Encoding.UTF8.GetString(plainBytes); return Encoding.UTF8.GetString(plainBytes);
} }
} }
} }