forked from JeffreySu/WeiXinMPSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'JeffreySu:Developer-TenpayV3' into Developer-TenpayV3
- Loading branch information
Showing
17 changed files
with
206 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3.Test/Properties/launchSettings.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3.Test/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Entities/PublicKeyCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Senparc.Weixin.TenPayV3.Entities | ||
{ | ||
/// <summary> | ||
/// 储存公钥 | ||
/// <para>Key:serial_no,Value:Key</para> | ||
/// </summary> | ||
public class PublicKeyCollection : ConcurrentDictionary<string, string> | ||
{ | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Exceptions/TenpaySecurityException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Senparc.Weixin.Exceptions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Senparc.Weixin.TenPayV3 | ||
{ | ||
public class TenpaySecurityException : WeixinException | ||
{ | ||
public TenpaySecurityException(string message, Exception inner, bool logged = false) : base(message, inner, logged) | ||
{ | ||
} | ||
|
||
public TenpaySecurityException(string message, bool logged = false) : this(message, null, logged) | ||
{ | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/Senparc.Weixin.TenPay/Senparc.Weixin.TenPayV3/Helpers/ApiSecurityHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Senparc.Weixin.TenPayV3.Apis.BasePay.Entities; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Senparc.Weixin.TenPayV3.Helpers | ||
{ | ||
public class ApiSecurityHelper | ||
{ | ||
/// <summary> | ||
/// 解密微信支付接口 ciphertext 内容 | ||
/// </summary> | ||
/// <returns></returns> | ||
public static string AesGcmDecryptCiphertext(string aes_key, string nonce, string associated_data, string ciphertext) | ||
{ | ||
|
||
//将解密所需数据转换为Bytes | ||
var keyBytes = Encoding.UTF8.GetBytes(aes_key); | ||
var nonceBytes = Encoding.UTF8.GetBytes(nonce); | ||
var associatedBytes = associated_data == null ? null : Encoding.UTF8.GetBytes(associated_data); | ||
|
||
//AEAD_AES_256_GCM 解密 | ||
var encryptedBytes = Convert.FromBase64String(ciphertext); | ||
//tag size is 16 TODO: what is tag size? | ||
var cipherBytes = encryptedBytes[..^16]; | ||
var tag = encryptedBytes[^16..]; | ||
var decryptedData = new byte[cipherBytes.Length]; | ||
using var cipher = new AesGcm(keyBytes); | ||
cipher.Decrypt(nonceBytes, cipherBytes, tag, decryptedData, associatedBytes); | ||
var decrypted_string = Encoding.UTF8.GetString(decryptedData); | ||
|
||
return decrypted_string; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.