From 6c33157d317c52caf57b1b500871c78c61ce3a9b Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Mon, 15 Jul 2024 12:56:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(work):=20`EncryptionKeyEntry`=20=E6=9E=84?= =?UTF-8?q?=E9=80=A0=E6=97=B6=E5=90=8C=E6=97=B6=E6=94=AF=E6=8C=81=20PKCS#1?= =?UTF-8?q?=20=E5=92=8C=20PKCS#8=20=E4=B8=A4=E7=A7=8D=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExtendedSDK/Finance/Settings/EncryptionKeyEntry.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SKIT.FlurlHttpClient.Wechat.Work/ExtendedSDK/Finance/Settings/EncryptionKeyEntry.cs b/src/SKIT.FlurlHttpClient.Wechat.Work/ExtendedSDK/Finance/Settings/EncryptionKeyEntry.cs index 3046e601..1a79404e 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Work/ExtendedSDK/Finance/Settings/EncryptionKeyEntry.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Work/ExtendedSDK/Finance/Settings/EncryptionKeyEntry.cs @@ -26,11 +26,14 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.ExtendedSDK.Finance.Settings [System.Text.Json.Serialization.JsonConstructor] public EncryptionKeyEntry(int version, string privateKey) { + privateKey = privateKey?.Trim()!; + if (version <= 0) throw new ArgumentException("The value of `version` can not be less than zero.", nameof(version)); if (string.IsNullOrEmpty(privateKey)) throw new ArgumentException("The value of `privateKey` can not be empty.", nameof(privateKey)); - if (!privateKey.Trim().StartsWith("-----BEGIN RSA PRIVATE KEY-----") || !privateKey.Trim().EndsWith("-----END RSA PRIVATE KEY-----")) + if (!(privateKey.StartsWith("-----BEGIN PRIVATE KEY-----") && privateKey.EndsWith("-----END PRIVATE KEY-----")) && + !(privateKey.StartsWith("-----BEGIN RSA PRIVATE KEY-----") && privateKey.EndsWith("-----END RSA PRIVATE KEY-----"))) throw new ArgumentException("The value of `privateKey` is an invalid private key file content.", nameof(privateKey)); Version = version;