Skip to content

Commit

Permalink
加载证书缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
my6521 committed Mar 15, 2024
1 parent b597d7f commit be90178
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/WWB.Paylink.BaoFooPay/WWB.Paylink.BaoFooPay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackageId>WWB.Paylink.BaoFooPay</PackageId>
<Version>1.0.4</Version>
<Version>1.0.5</Version>
<Authors>my6521</Authors>
<Description>惠收钱SDK。</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>WWB.Paylink.BaoFooTransfer</PackageId>
<Version>1.0.4</Version>
<Version>1.0.5</Version>
<Authors>my6521</Authors>
<Description>宝付代付SDK。</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
2 changes: 1 addition & 1 deletion src/WWB.Paylink.JoinPay/WWB.Paylink.JoinPay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackageId>WWB.Paylink.JoinPay</PackageId>
<Version>1.0.4</Version>
<Version>1.0.5</Version>
<Authors>my6521</Authors>
<Description>汇聚支付SDK</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
21 changes: 20 additions & 1 deletion src/WWB.Paylink.Utility/Security/RsaReadUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
using Org.BouncyCastle.Utilities.Encoders;
using Org.BouncyCastle.X509;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace WWB.Paylink.Utility.Security
{
public static class RsaReadUtil
{
private static Dictionary<string, AsymmetricKeyParameter> m_keys = new Dictionary<string, AsymmetricKeyParameter>();

/// <summary>
/// 读取私钥
/// </summary>
Expand All @@ -18,6 +21,11 @@ public static class RsaReadUtil
/// <returns></returns>
public static AsymmetricKeyParameter GetPrivateKeyFromFile(string path, string pwd)
{
if (m_keys.ContainsKey(path))
{
return m_keys[path];
}

var passwd = pwd.ToCharArray();
var store = new Pkcs12StoreBuilder().Build();
//path路径下证书
Expand All @@ -34,6 +42,8 @@ public static AsymmetricKeyParameter GetPrivateKeyFromFile(string path, string p
}

var keyEntry = store.GetKey(alias);
m_keys[path] = keyEntry.Key;

return keyEntry.Key;
}

Expand All @@ -45,6 +55,11 @@ public static AsymmetricKeyParameter GetPrivateKeyFromFile(string path, string p
/// <exception cref="Exception"></exception>
public static AsymmetricKeyParameter GetPublicKeyFromFile(string path)
{
if (m_keys.ContainsKey(path))
{
return m_keys[path];
}

string line = null;
var keyBuffer = new StringBuilder();

Expand All @@ -65,7 +80,11 @@ public static AsymmetricKeyParameter GetPublicKeyFromFile(string path)
}

var cerObj = new X509CertificateParser().ReadCertificate(Base64.Decode(keyBuffer.ToString()));
return cerObj.GetPublicKey();
var result = cerObj.GetPublicKey();

m_keys[path] = result;

return result;
}
}
}
2 changes: 1 addition & 1 deletion src/WWB.Paylink.Utility/WWB.Paylink.Utility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>WWB.Paylink.Utility</PackageId>
<Version>1.0.4</Version>
<Version>1.0.5</Version>
<Authors>my6521</Authors>
<Description>支付帮助类。</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down

0 comments on commit be90178

Please sign in to comment.