AsymmetricManager.cs 995 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. namespace PaySharp.Alipay.Util.Asymmetric
  3. {
  4. /// <summary>
  5. /// 非对称加密算法管理类
  6. /// </summary>
  7. public static class AsymmetricManager
  8. {
  9. /// <summary>
  10. /// 根据算法名称(RSA、RSA2、SM2)实例化具体算法的加密器
  11. /// </summary>
  12. /// <param name="type">算法名称</param>
  13. /// <returns>具体算法的加密器</returns>
  14. public static IAsymmetricEncryptor GetByName(string type)
  15. {
  16. if ("RSA".Equals(type))
  17. {
  18. return new RSAEncryptor();
  19. }
  20. if ("RSA2".Equals(type))
  21. {
  22. return new RSA2Encryptor();
  23. }
  24. if ("SM2".Equals(type))
  25. {
  26. return new SM2Encryptor();
  27. }
  28. throw new Exception("无效的非对称加密类型:[" + type + "],可选值为:RSA、RSA2和SM2。");
  29. }
  30. }
  31. }