DotNetCore.SKIT.FlurlHttpCl.../test/SKIT.FlurlHttpClient.Wechat.Work.UnitTests/TestCase_ToolsRSAUtilityTests.cs

24 lines
3.2 KiB
C#

using Xunit;
namespace SKIT.FlurlHttpClient.Wechat.Work.UnitTests
{
using SKIT.FlurlHttpClient.Primitives;
public class TestCase_ToolsRSAUtilityTests
{
// 此处测试的 RSA 公钥/私钥是自签名生成的,仅供执行 RSA 相关的单元测试,不能用于调用企业微信 API
private const string RSA_PEM_PUBLIC_KEY = "-----BEGIN RSA PUBLIC KEY-----MIIBCgKCAQEAuwQaAJGSMda9ESGhyY2PPuVds8OjoqyRi29IEQgXJ03Bu/o6KjZVbPQT4n3WncrT0c92zA6lazJDbaXQkHlvdDpOo3FqBvczDDT0jveCfg7azeOmRxHE8P/iWOkQm+Dhk5hnmfxqtX7pzu2quzuGt9JH4FxPhNEOkn4/uRn+1qo/KrrU2Db09gm3aPjOWTT5XEVD9tPNTsZr/vaKYGCQKTqeRWhDGL3JAgyyLgGyGTAOTt0gl0MPG/O6omwELTVQdzXqyRrKgx0tEhIKoeYBVPKbWOTJyXsRO9dcfXKu56jry9QyqjFHcVtfCuphOaFIhGUEDYuAIJsqBKJqrSZoVQIDAQAB-----END RSA PUBLIC KEY-----";
private const string RSA_PEM_PRIVATE_KEY = "-----BEGIN RSA PRIVATE KEY-----MIIEogIBAAKCAQEAuwQaAJGSMda9ESGhyY2PPuVds8OjoqyRi29IEQgXJ03Bu/o6KjZVbPQT4n3WncrT0c92zA6lazJDbaXQkHlvdDpOo3FqBvczDDT0jveCfg7azeOmRxHE8P/iWOkQm+Dhk5hnmfxqtX7pzu2quzuGt9JH4FxPhNEOkn4/uRn+1qo/KrrU2Db09gm3aPjOWTT5XEVD9tPNTsZr/vaKYGCQKTqeRWhDGL3JAgyyLgGyGTAOTt0gl0MPG/O6omwELTVQdzXqyRrKgx0tEhIKoeYBVPKbWOTJyXsRO9dcfXKu56jry9QyqjFHcVtfCuphOaFIhGUEDYuAIJsqBK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6WF1Z7FNsQlxZxJrzZrO82OIWOPucaPNNOn0I/V4ttaFo7GSWvRX16ADvA0dNMXuB+5syGt5dgDPCOtTXzPZq0Twzwgc5uyknkS1cn9Gt+a0oZ9/+zGzjKK2tcX+HwM7r6bTaxVNzjd6Hg=-----END RSA PRIVATE KEY-----";
[Fact(DisplayName = "测试用例:使用 RSA 私钥解密")]
public void TestRSADecrypt()
{
string cipherText = "ewwZ8LmXVJpkJpj/JWcz16L4bePAGcf3Fi2EKyC6AS3JsF5u4aku7iOYqtcAczjoYwE1fqSadRd6YTrWr3tLP3uWFYmhqthQoaAcjmQS0vHYRFeS1V7q5hbziVLRp7C42S4YrvqXAmSmUyjPUXG5tXFVchARVkTr1F53HGoPP+iBg+i8y0uJK4FgiuKraFgdtKofv/k5/30xKzRHxdLFCFt1rF7wL+Hk/7Bl0tFZM/rfhmuvwbf46zWhxKKviAge+61tEot4QCSBLnAFpPuSQsTOOSOrlCl92DwW54dWdlWwhqkTVHdm6pXEdUE66y1yoZkXfpqjnONjta0njqN/Jw==";
string actualPlain = Utilities.RSAUtility.DecryptWithECB(RSA_PEM_PRIVATE_KEY, new EncodedString(cipherText, EncodingKinds.Base64))!;
string expectedPlain = "RsaDecryptTest";
Assert.Equal(expectedPlain, actualPlain);
}
}
}