Skip to content

Commit

Permalink
[Security] 新增 OaepSHA1WithRSA 类,删除 RSAUtilities、RSA_ECB_OAEPWithSHA1A…
Browse files Browse the repository at this point in the history
…ndMGF1Padding
  • Loading branch information
Roc committed Dec 18, 2019
1 parent 911283f commit af884ae
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@
<PackageTags>Essensoft;Payment;Security</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Portable.BouncyCastle" Version="1.8.5.2" />
</ItemGroup>

</Project>
47 changes: 47 additions & 0 deletions src/Essensoft.AspNetCore.Payment.Security/OaepSHA1WithRSA.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Security.Cryptography;
using System.Text;

namespace Essensoft.AspNetCore.Payment.Security
{
public static class OaepSHA1WithRSA
{
public static string Encrypt(string data, string publicKey)
{
if (string.IsNullOrEmpty(data))
{
throw new ArgumentNullException(nameof(data));
}

if (string.IsNullOrEmpty(publicKey))
{
throw new ArgumentNullException(nameof(publicKey));
}

using (var rsa = RSA.Create())
{
rsa.ImportRSAPublicKey(Convert.FromBase64String(publicKey), out var _);
return Convert.ToBase64String(rsa.Encrypt(Encoding.UTF8.GetBytes(data), RSAEncryptionPadding.OaepSHA1));
}
}

public static string Decrypt(string data, string privateKey)
{
if (string.IsNullOrEmpty(data))
{
throw new ArgumentNullException(nameof(data));
}

if (string.IsNullOrEmpty(privateKey))
{
throw new ArgumentNullException(nameof(privateKey));
}

using (var rsa = RSA.Create())
{
rsa.ImportRSAPrivateKey(Convert.FromBase64String(privateKey), out var _);
return Encoding.UTF8.GetString(rsa.Decrypt(Convert.FromBase64String(data), RSAEncryptionPadding.OaepSHA1));
}
}
}
}
28 changes: 0 additions & 28 deletions src/Essensoft.AspNetCore.Payment.Security/RSAUtilities.cs

This file was deleted.

This file was deleted.

0 comments on commit af884ae

Please sign in to comment.