NewGaoKaoApi/PaymentSDK/AliPay/Util/Asymmetric/AsymmetricManager.cs

32 lines
942 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

namespace Aop.Api.Util.Asymmetric
{
/// <summary>
/// 非对称加密算法管理类
/// </summary>
public static class AsymmetricManager
{
/// <summary>
/// 根据算法名称RSA、RSA2、SM2实例化具体算法的加密器
/// </summary>
/// <param name="type">算法名称</param>
/// <returns>具体算法的加密器</returns>
public static IAsymmetricEncryptor GetByName(string type)
{
if ("RSA".Equals(type))
{
return new RSAEncryptor();
}
if ("RSA2".Equals(type))
{
return new RSA2Encryptor();
}
if ("SM2".Equals(type))
{
return new SM2Encryptor();
}
throw new AopException("无效的非对称加密类型:[" + type + "]可选值为RSA、RSA2和SM2。");
}
}
}