refactor(tenpaybusiness): 优化加解密及哈希算法工具类

This commit is contained in:
Fu Diwei
2024-02-05 10:53:54 +08:00
committed by RHQYZ
parent a11df544e5
commit 70315cd128
16 changed files with 576 additions and 388 deletions

View File

@@ -2,6 +2,8 @@ using Xunit;
namespace SKIT.FlurlHttpClient.Wechat.TenpayBusiness.UnitTests
{
using SKIT.FlurlHttpClient.Primitives;
public class TestCase_ToolsSM4UtilityTests
{
[Fact(DisplayName = "测试用例SM4 加密")]
@@ -11,7 +13,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayBusiness.UnitTests
string iv = "OGE2YzRkZGQ4YTZjNGRkZA==";
string plainText = "Awesome SKIT.FlurlHttpClient.Wechat.TenpayBusiness!";
string actualCipher = Utilities.SM4Utility.EncryptWithCBC(key: key, iv: iv, plainText: plainText);
string actualCipher = Utilities.SM4Utility.EncryptWithCBC(encodingKey: (EncodedString)key, encodingIV: (EncodedString)iv, plainData: plainText)!;
string expectedCipher = "Fm3z4Ipjuaj4oQLfxpTrvoZm5JdbjvjrJo3PRhvSsOppk8/PN+izH3Wo9Rz6V85mpq6X1cGul8U7jjaAl1PWpg==";
Assert.Equal(expectedCipher, actualCipher);
@@ -24,7 +26,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayBusiness.UnitTests
string iv = "OGE2YzRkZGQ4YTZjNGRkZA==";
string cipherText = "Fm3z4Ipjuaj4oQLfxpTrvoZm5JdbjvjrJo3PRhvSsOppk8/PN+izH3Wo9Rz6V85mpq6X1cGul8U7jjaAl1PWpg==";
string actualPlain = Utilities.SM4Utility.DecryptWithCBC(key: key, iv: iv, cipherText: cipherText);
string actualPlain = Utilities.SM4Utility.DecryptWithCBC(encodingKey: (EncodedString)key, encodingIV: (EncodedString)iv, encodingCipher: (EncodedString)cipherText)!;
string expectedPlain = "Awesome SKIT.FlurlHttpClient.Wechat.TenpayBusiness!";
Assert.Equal(expectedPlain, actualPlain);