-
-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security] 新增 OaepSHA1WithRSA 类,删除 RSAUtilities、RSA_ECB_OAEPWithSHA1A…
…ndMGF1Padding
- Loading branch information
Roc
committed
Dec 18, 2019
1 parent
911283f
commit af884ae
Showing
4 changed files
with
47 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/Essensoft.AspNetCore.Payment.Security/OaepSHA1WithRSA.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
src/Essensoft.AspNetCore.Payment.Security/RSA_ECB_OAEPWithSHA1AndMGF1Padding.cs
This file was deleted.
Oops, something went wrong.