Ver código fonte

AsymmetricKeyParameter => ICipherParameters

Roc 6 anos atrás
pai
commit
2dfb824526

+ 2 - 2
src/Essensoft.AspNetCore.Payment.JDPay/JDPayOptions.cs

@@ -8,8 +8,8 @@ namespace Essensoft.AspNetCore.Payment.JDPay
     public class JDPayOptions
     {
         internal byte[] DesKeyBase64;
-        internal AsymmetricKeyParameter PrivateKey;
-        internal AsymmetricKeyParameter PublicKey;
+        internal ICipherParameters PrivateKey;
+        internal ICipherParameters PublicKey;
 
         private string desKey;
         private string rsaPrivateKey;

+ 2 - 2
src/Essensoft.AspNetCore.Payment.JDPay/Utility/JDPaySecurity.cs

@@ -106,14 +106,14 @@ namespace Essensoft.AspNetCore.Payment.JDPay.Utility
             return sb.Remove(sb.Length - 1, 1).ToString();
         }
 
-        public static string RSASign(string sourceSignString, AsymmetricKeyParameter privateKey)
+        public static string RSASign(string sourceSignString, ICipherParameters privateKey)
         {
             var sha256SourceSignString = SHA256.Compute(sourceSignString);
             var newsks = RSA_ECB_PKCS1Padding.Encrypt(Encoding.UTF8.GetBytes(sha256SourceSignString), privateKey);
             return Convert.ToBase64String(newsks, Base64FormattingOptions.InsertLineBreaks);
         }
 
-        public static bool RSACheckContent(string content, string sign, AsymmetricKeyParameter publicKey)
+        public static bool RSACheckContent(string content, string sign, ICipherParameters publicKey)
         {
             var sha256SourceSignString = SHA256.Compute(content);
             var decryptArr = RSA_ECB_PKCS1Padding.Decrypt(Convert.FromBase64String(sign), publicKey);

+ 2 - 2
src/Essensoft.AspNetCore.Payment.LianLianPay/LianLianPayOptions.cs

@@ -6,8 +6,8 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay
 {
     public class LianLianPayOptions
     {
-        internal AsymmetricKeyParameter PrivateKey;
-        internal AsymmetricKeyParameter PublicKey;
+        internal ICipherParameters PrivateKey;
+        internal ICipherParameters PublicKey;
 
         private string rsaPrivateKey;
         private string rsaPublicKey;

+ 4 - 4
src/Essensoft.AspNetCore.Payment.LianLianPay/Utility/LianLianPaySecurity.cs

@@ -32,7 +32,7 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay.Utility
             return sb.Remove(sb.Length - 1, 1).ToString();
         }
 
-        public static string Encrypt(string plaintext, AsymmetricKeyParameter public_key)
+        public static string Encrypt(string plaintext, ICipherParameters public_key)
         {
             var hmack_key = Guid.NewGuid().ToString("N");
             var version = "lianpay1_0_1";
@@ -41,7 +41,7 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay.Utility
             return LianlianpayEncrypt(plaintext, public_key, hmack_key, version, aes_key, nonce);
         }
 
-        public static string Decrypt(string ciphertext, AsymmetricKeyParameter private_key)
+        public static string Decrypt(string ciphertext, ICipherParameters private_key)
         {
             if (!string.IsNullOrEmpty(ciphertext))
             {
@@ -55,7 +55,7 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay.Utility
             return string.Empty;
         }
 
-        private static string LianlianpayEncrypt(string req, AsymmetricKeyParameter public_key, string hmack_key, string version, string aes_key, string nonce)
+        private static string LianlianpayEncrypt(string req, ICipherParameters public_key, string hmack_key, string version, string aes_key, string nonce)
         {
             var b64Hmack_key = RSA_ECB_OAEPWithSHA1AndMGF1Padding.Encrypt(hmack_key, public_key);
             var b64Aes_key = RSA_ECB_OAEPWithSHA1AndMGF1Padding.Encrypt(aes_key, public_key);
@@ -68,7 +68,7 @@ namespace Essensoft.AspNetCore.Payment.LianLianPay.Utility
             return version + "$" + b64Hmack_key + "$" + b64Aes_key + "$" + b64Nonce + "$" + encry + "$" + b64Sign;
         }
 
-        private static string LianlianpayDecrypt(string base64_ciphertext, string base64_encrypted_aes_key, string base64_nonce, AsymmetricKeyParameter trader_pri_key)
+        private static string LianlianpayDecrypt(string base64_ciphertext, string base64_encrypted_aes_key, string base64_nonce, ICipherParameters trader_pri_key)
         {
             var key = RSA_ECB_OAEPWithSHA1AndMGF1Padding.Decrypt(base64_encrypted_aes_key, trader_pri_key);
             var nonce = Convert.FromBase64String(base64_nonce);

+ 2 - 2
src/Essensoft.AspNetCore.Payment.Security/MD5WithRSA.cs

@@ -7,7 +7,7 @@ namespace Essensoft.AspNetCore.Payment.Security
 {
     public class MD5WithRSA
     {
-        public static string SignData(string data, AsymmetricKeyParameter key)
+        public static string SignData(string data, ICipherParameters key)
         {
             var signer = SignerUtilities.GetSigner("MD5WithRSA");
             signer.Init(true, key);
@@ -16,7 +16,7 @@ namespace Essensoft.AspNetCore.Payment.Security
             return Convert.ToBase64String(signer.GenerateSignature());
         }
 
-        public static bool VerifyData(string data, string sign, AsymmetricKeyParameter key)
+        public static bool VerifyData(string data, string sign, ICipherParameters key)
         {
             var verifier = SignerUtilities.GetSigner("MD5WithRSA");
             verifier.Init(false, key);

+ 3 - 3
src/Essensoft.AspNetCore.Payment.Security/RSAUtilities.cs

@@ -11,13 +11,13 @@ namespace Essensoft.AspNetCore.Payment.Security
 {
     public class RSAUtilities
     {
-        public static AsymmetricKeyParameter GetKeyParameterFormPrivateKey(string privateKey)
+        public static ICipherParameters GetKeyParameterFormPrivateKey(string privateKey)
         {
             var keyStructure = RsaPrivateKeyStructure.GetInstance(Convert.FromBase64String(privateKey));
             return new RsaPrivateCrtKeyParameters(keyStructure.Modulus, keyStructure.PublicExponent, keyStructure.PrivateExponent, keyStructure.Prime1, keyStructure.Prime2, keyStructure.Exponent1, keyStructure.Exponent2, keyStructure.Coefficient);
         }
 
-        public static AsymmetricKeyParameter GetKeyParameterFormPublicKey(string publicKey)
+        public static ICipherParameters GetKeyParameterFormPublicKey(string publicKey)
         {
             return PublicKeyFactory.CreateKey(Convert.FromBase64String(publicKey));
         }
@@ -48,7 +48,7 @@ namespace Essensoft.AspNetCore.Payment.Security
             };
         }
 
-        public static AsymmetricKeyParameter GetPublicKeyParameterFormAsn1PublicKey(string publicKey)
+        public static ICipherParameters GetPublicKeyParameterFormAsn1PublicKey(string publicKey)
         {
             var keyStructure = RsaPublicKeyStructure.GetInstance(Asn1Object.FromByteArray(Convert.FromBase64String(publicKey)));
             return new RsaKeyParameters(false, keyStructure.Modulus, keyStructure.PublicExponent);

+ 4 - 4
src/Essensoft.AspNetCore.Payment.Security/RSA_ECB_OAEPWithSHA1AndMGF1Padding.cs

@@ -7,28 +7,28 @@ namespace Essensoft.AspNetCore.Payment.Security
 {
     public class RSA_ECB_OAEPWithSHA1AndMGF1Padding
     {
-        public static byte[] Encrypt(byte[] data, AsymmetricKeyParameter key)
+        public static byte[] Encrypt(byte[] data, ICipherParameters key)
         {
             var cipher = CipherUtilities.GetCipher("RSA/ECB/OAEPWithSHA1AndMGF1Padding");
             cipher.Init(true, key);
             return cipher.DoFinal(data);
         }
 
-        public static byte[] Decrypt(byte[] data, AsymmetricKeyParameter key)
+        public static byte[] Decrypt(byte[] data, ICipherParameters key)
         {
             var cipher = CipherUtilities.GetCipher("RSA/ECB/OAEPWithSHA1AndMGF1Padding");
             cipher.Init(false, key);
             return cipher.DoFinal(data);
         }
 
-        public static string Encrypt(string data, AsymmetricKeyParameter key)
+        public static string Encrypt(string data, ICipherParameters key)
         {
             var cipher = CipherUtilities.GetCipher("RSA/ECB/OAEPWithSHA1AndMGF1Padding");
             cipher.Init(true, key);
             return Convert.ToBase64String(cipher.DoFinal(Encoding.UTF8.GetBytes(data)));
         }
 
-        public static string Decrypt(string data, AsymmetricKeyParameter key)
+        public static string Decrypt(string data, ICipherParameters key)
         {
             var cipher = CipherUtilities.GetCipher("RSA/ECB/OAEPWithSHA1AndMGF1Padding");
             cipher.Init(false, key);

+ 5 - 5
src/Essensoft.AspNetCore.Payment.Security/RSA_ECB_PKCS1Padding.cs

@@ -7,28 +7,28 @@ namespace Essensoft.AspNetCore.Payment.Security
 {
     public class RSA_ECB_PKCS1Padding
     {
-        public static byte[] Encrypt(byte[] data, AsymmetricKeyParameter parameters)
+        public static byte[] Encrypt(byte[] data, ICipherParameters key)
         {
             var cipher = CipherUtilities.GetCipher("RSA/ECB/PKCS1Padding");
-            cipher.Init(true, parameters);
+            cipher.Init(true, key);
             return cipher.DoFinal(data);
         }
 
-        public static byte[] Decrypt(byte[] data, AsymmetricKeyParameter key)
+        public static byte[] Decrypt(byte[] data, ICipherParameters key)
         {
             var cipher = CipherUtilities.GetCipher("RSA/ECB/PKCS1Padding");
             cipher.Init(false, key);
             return cipher.DoFinal(data);
         }
 
-        public static string Encrypt(string data, AsymmetricKeyParameter key)
+        public static string Encrypt(string data, ICipherParameters key)
         {
             var cipher = CipherUtilities.GetCipher("RSA/ECB/PKCS1Padding");
             cipher.Init(true, key);
             return Convert.ToBase64String(cipher.DoFinal(Encoding.UTF8.GetBytes(data)));
         }
 
-        public static string Decrypt(string data, AsymmetricKeyParameter key)
+        public static string Decrypt(string data, ICipherParameters key)
         {
             var cipher = CipherUtilities.GetCipher("RSA/ECB/PKCS1Padding");
             cipher.Init(false, key);

+ 2 - 2
src/Essensoft.AspNetCore.Payment.Security/RSA_NONE_PKCS1Padding.cs

@@ -21,14 +21,14 @@ namespace Essensoft.AspNetCore.Payment.Security
             return cipher.DoFinal(data);
         }
 
-        public static string Encrypt(string data, AsymmetricKeyParameter key)
+        public static string Encrypt(string data, ICipherParameters key)
         {
             var cipher = CipherUtilities.GetCipher("RSA/NONE/PKCS1Padding");
             cipher.Init(true, key);
             return Convert.ToBase64String(cipher.DoFinal(Encoding.UTF8.GetBytes(data)));
         }
 
-        public static string Decrypt(string data, AsymmetricKeyParameter key)
+        public static string Decrypt(string data, ICipherParameters key)
         {
             var cipher = CipherUtilities.GetCipher("RSA/NONE/PKCS1Padding");
             cipher.Init(false, key);

+ 2 - 2
src/Essensoft.AspNetCore.Payment.Security/SHA1WithRSA.cs

@@ -7,7 +7,7 @@ namespace Essensoft.AspNetCore.Payment.Security
 {
     public class SHA1WithRSA
     {
-        public static string SignData(string data, AsymmetricKeyParameter key)
+        public static string SignData(string data, ICipherParameters key)
         {
             var signer = SignerUtilities.GetSigner("SHA1WithRSA");
             signer.Init(true, key);
@@ -16,7 +16,7 @@ namespace Essensoft.AspNetCore.Payment.Security
             return Convert.ToBase64String(signer.GenerateSignature());
         }
 
-        public static bool VerifyData(string data, string sign, AsymmetricKeyParameter key)
+        public static bool VerifyData(string data, string sign, ICipherParameters key)
         {
             var verifier = SignerUtilities.GetSigner("SHA1WithRSA");
             verifier.Init(false, key);

+ 1 - 1
src/Essensoft.AspNetCore.Payment.UnionPay/Utility/UnionPayCertificate.cs

@@ -7,6 +7,6 @@ namespace Essensoft.AspNetCore.Payment.UnionPay.Utility
     {
         public X509Certificate cert;
         public string certId;
-        public AsymmetricKeyParameter key;
+        public ICipherParameters key;
     }
 }

+ 4 - 4
src/Essensoft.AspNetCore.Payment.UnionPay/Utility/UnionPaySignature.cs

@@ -20,7 +20,7 @@ namespace Essensoft.AspNetCore.Payment.UnionPay.Utility
 
         private static readonly Dictionary<string, X509Certificate> validateCerts = new Dictionary<string, X509Certificate>();
 
-        public static void Sign(Dictionary<string, string> reqData, string certId, AsymmetricKeyParameter parameters, string secureKey)
+        public static void Sign(Dictionary<string, string> reqData, string certId, ICipherParameters key, string secureKey)
         {
             if (!reqData.ContainsKey("signMethod"))
             {
@@ -30,7 +30,7 @@ namespace Essensoft.AspNetCore.Payment.UnionPay.Utility
             var signMethod = reqData["signMethod"];
             if ("01" == signMethod)
             {
-                SignByCertInfo(reqData, certId, parameters);
+                SignByCertInfo(reqData, certId, key);
             }
             else if ("11" == signMethod || "12" == signMethod)
             {
@@ -81,7 +81,7 @@ namespace Essensoft.AspNetCore.Payment.UnionPay.Utility
             return result;
         }
 
-        public static void SignByCertInfo(Dictionary<string, string> data, string certId, ICipherParameters parameters)
+        public static void SignByCertInfo(Dictionary<string, string> data, string certId, ICipherParameters key)
         {
             if (!data.ContainsKey("signMethod"))
             {
@@ -100,7 +100,7 @@ namespace Essensoft.AspNetCore.Payment.UnionPay.Utility
 
                 var stringData = GetSignContent(data, true, false);
                 var stringSignDigest = SHA256.Compute(stringData);
-                var stringSign = SHA256WithRSA.SignData(stringSignDigest, parameters);
+                var stringSign = SHA256WithRSA.SignData(stringSignDigest, key);
 
                 //设置签名域值
                 data["signature"] = stringSign;

+ 1 - 1
src/Essensoft.AspNetCore.Payment.WeChatPay/WeChatPayOptions.cs

@@ -6,7 +6,7 @@ namespace Essensoft.AspNetCore.Payment.WeChatPay
 {
     public class WeChatPayOptions
     {
-        internal AsymmetricKeyParameter PublicKey;
+        internal ICipherParameters PublicKey;
 
         private string rsaPublicKey;