mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2026-02-10 17:56:21 +08:00
feat(work): EncryptionKeyEntry 构造时同时支持 PKCS#1 和 PKCS#8 两种格式
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user