mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-12-29 09:54:44 +08:00
test(wxapi): 增加 AES-CBC 解密的单元测试用例
This commit is contained in:
@@ -4,6 +4,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.UnitTests
|
||||
@@ -16,9 +18,9 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.UnitTests
|
||||
string rawData = "jsapi_ticket=HoagFKDcsGMVCIY2vOjf9nGrZ3eaM0qXs5ROFN_3k_HrGc0VocemA6wMXkvrL-Ei4IitXxwKF62CJWR8mWXZ3Q&noncestr=e7b435f73835402da44f16640ddc8696×tamp=1621348162&url=https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign";
|
||||
|
||||
string actualHash = Security.SHA1Utility.Hash(rawData);
|
||||
string expectdHash = "b214ea1f8ae019c207f8c6ffb843c8474cbab28c";
|
||||
string expectedHash = "b214ea1f8ae019c207f8c6ffb843c8474cbab28c";
|
||||
|
||||
Assert.Equal(expectdHash, actualHash, ignoreCase: true);
|
||||
Assert.Equal(expectedHash, actualHash, ignoreCase: true);
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "信息摘要(HMAC-SHA-256)")]
|
||||
@@ -28,9 +30,23 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.UnitTests
|
||||
string rawData = "appid=wx1234567&offer_id=12345678&openid=odkx20ENSNa2w5y3g_qOkOvBNM1g&pf=android&ts=1507530737&zone_id=1&org_loc=/cgi-bin/midas/getbalance&method=POST&secret=zNLgAGgqsEWJOg1nFVaO5r7fAlIQxr1u";
|
||||
|
||||
string actualHash = Security.HMACSHA256Utility.Hash(secret, rawData);
|
||||
string expectdHash = "1ad64e8dcb2ec1dc486b7fdf01f4a15159fc623dc3422470e51cf6870734726b";
|
||||
string expectedHash = "1ad64e8dcb2ec1dc486b7fdf01f4a15159fc623dc3422470e51cf6870734726b";
|
||||
|
||||
Assert.Equal(expectdHash, actualHash, ignoreCase: true);
|
||||
Assert.Equal(expectedHash, actualHash, ignoreCase: true);
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "AES-CBC 解密")]
|
||||
public void AesCbcDecryptTest()
|
||||
{
|
||||
string iv = "KEWv/gyiIwAfHvjrLeaX6w==";
|
||||
string key = "YZJqKnNFi0KAiKUc0ggC2g==";
|
||||
string cipherData = "Gu2PVnxVWl+jK4F8c0liG1TiwQfaibvddu8eU1zWDDmVpPlM8ewsDzDr3l8VMY01ifZgFWNsr5QyBG0IKwM6lJNXzZHkaK9AQ4ZkVq7PYwdqNQkrg0QmKzntLMTRVNuY+TqPhXGPrOhup/orxwwCUBqheFPPwVbMeOdwrpVNyOdtsHRWQUefXN5UtDBb40pPHon4DbiHBQb5TjBPMrEF2Q==";
|
||||
|
||||
string actualPlainData = Utilities.AESUtility.DecryptWithCBC(encodingKey: key, encodingIV: iv, encodingCipherText: cipherData).Trim();
|
||||
string actualPhoneNumber = JsonConvert.DeserializeObject<JToken>(actualPlainData)["phoneNumber"].ToObject<string>();
|
||||
string expectedPhoneNumber = "18677245613";
|
||||
|
||||
Assert.Equal(expectedPhoneNumber, actualPhoneNumber, ignoreCase: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.UnitTests
|
||||
string reqCipherText = "RypEvHKD8QQKFhvQ6QleEB4J58tiPdvo+rtK1I9qca6aM/wvqnLSV5zEPeusUiX5L5X/0lWfrf0QADHHhGd3QczcdCUpj911L3vg3W/sYYvuJTs3TUUkSUXxaccAS0qhxchrRYt66wiSpGLYL42aM6A8dTT+6k4aSknmPj48kzJs8qLjvd4Xgpue06DOdnLxAUHzM6+kDZ+HMZfJYuR+LtwGc2hgf5gsijff0ekUNXZiqATP7PF5mZxZ3Izoun1s4zG4LUMnvw2r+KqCKIw+3IQH03v+BCA9nMELNqbSf6tiWSrXJB3LAVGUcallcrw8V2t9EL4EhzJWrQUax5wLVMNS0+rUPA3k22Ncx4XXZS9o0MBH27Bo6BpNelZpS+/uh9KsNlY6bHCmJU9p8g7m3fVKn28H3KDYA5Pl/T8Z1ptDAVe0lXdQ2YoyyH2uyPIGHBZZIs2pDBS8R07+qN+E7Q==";
|
||||
|
||||
string actualPlain = Utilities.WxBizMsgCryptor.AESDecrypt(reqCipherText, aesKey, out string actualAppId);
|
||||
string expectdPlain = "<xml><ToUserName><![CDATA[wx5823bf96d3bd56c7]]></ToUserName>\n<FromUserName><![CDATA[mycreate]]></FromUserName>\n<CreateTime>1409659813</CreateTime>\n<MsgType><![CDATA[text]]></MsgType>\n<Content><![CDATA[hello]]></Content>\n<MsgId>4561255354251345929</MsgId>\n<AgentID>218</AgentID>\n</xml>";
|
||||
string expectedPlain = "<xml><ToUserName><![CDATA[wx5823bf96d3bd56c7]]></ToUserName>\n<FromUserName><![CDATA[mycreate]]></FromUserName>\n<CreateTime>1409659813</CreateTime>\n<MsgType><![CDATA[text]]></MsgType>\n<Content><![CDATA[hello]]></Content>\n<MsgId>4561255354251345929</MsgId>\n<AgentID>218</AgentID>\n</xml>";
|
||||
|
||||
Assert.Equal(expectdPlain, actualPlain);
|
||||
Assert.Equal(expectedPlain, actualPlain);
|
||||
Assert.Equal(appId, actualAppId);
|
||||
Assert.True(Utilities.WxBizMsgCryptor.VerifySignature(token, reqTimeStamp, reqNonce, reqCipherText, reqMsgSig));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user