Skip to content

Commit

Permalink
[WeChatPay.V3] 修正 配置p12证书,无法解密敏感信息。
Browse files Browse the repository at this point in the history
  • Loading branch information
roc916 committed May 15, 2023
1 parent 9169ef4 commit 47743a5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Essensoft.Paylink.WeChatPay/V3/WeChatPayClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public async Task<T> ExecuteAsync<T>(IWeChatPayPrivacyGetRequest<T> request, WeC
}

// 解密敏感信息
DecryptPrivacyProperty(response, options.APIPrivateKey);
DecryptPrivacyProperty(response, options.RSAPrivateKey);

return response;
}
Expand Down Expand Up @@ -222,7 +222,7 @@ public async Task<T> ExecuteAsync<T>(IWeChatPayPrivacyPostRequest<T> request, We
}

// 解密敏感信息
DecryptPrivacyProperty(response, options.APIPrivateKey);
DecryptPrivacyProperty(response, options.RSAPrivateKey);

return response;
}
Expand Down Expand Up @@ -324,7 +324,7 @@ private static void EncryptPrivacyProperty(WeChatPayObject obj, RSA rsa)
/// <remarks>
/// <para><a href="https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_3.shtml">敏感信息加解密</a></para>
/// </remarks>
private static void DecryptPrivacyProperty(WeChatPayObject obj, string privateKey)
private static void DecryptPrivacyProperty(WeChatPayObject obj, RSA rsa)
{
foreach (var propertyInfo in obj.GetType().GetProperties())
{
Expand All @@ -344,7 +344,7 @@ private static void DecryptPrivacyProperty(WeChatPayObject obj, string privateKe
}

// 解密并将明文设置回对象
var ciphertext = OaepSHA1WithRSA.Decrypt(strValue, privateKey);
var ciphertext = OaepSHA1WithRSA.Decrypt(rsa, strValue);
propertyInfo.SetValue(obj, ciphertext);
}
else if (propertyInfo.PropertyType.IsClass) // 解密子对象
Expand All @@ -355,7 +355,7 @@ private static void DecryptPrivacyProperty(WeChatPayObject obj, string privateKe
{
foreach (var item in array)
{
DecryptPrivacyProperty(item, privateKey);
DecryptPrivacyProperty(item, rsa);
}
}
}
Expand All @@ -365,15 +365,15 @@ private static void DecryptPrivacyProperty(WeChatPayObject obj, string privateKe
{
foreach (var item in enumerable)
{
DecryptPrivacyProperty(item, privateKey);
DecryptPrivacyProperty(item, rsa);
}
}
}
else if(typeof(WeChatPayObject).IsAssignableFrom(propertyInfo.PropertyType))
{
if (propertyInfo.GetValue(obj) is WeChatPayObject wcpObj)
{
DecryptPrivacyProperty(wcpObj, privateKey);
DecryptPrivacyProperty(wcpObj, rsa);
}
}
}
Expand Down

0 comments on commit 47743a5

Please sign in to comment.