平安校园
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

93 lines
1.8 KiB

  1. //
  2. namespace SafeCampus.Core.Utils;
  3. /// <summary>
  4. /// 加解密功能
  5. /// </summary>
  6. public class CryptogramUtil
  7. {
  8. #region SM2
  9. /// <summary>
  10. /// SM2解密
  11. /// </summary>
  12. /// <param name="str">密文</param>
  13. /// <returns>明文</returns>
  14. public static string Sm2Decrypt(string str)
  15. {
  16. // 解密
  17. if (!string.IsNullOrWhiteSpace(str))
  18. return SM2Util.Decrypt(str);
  19. try
  20. {
  21. // // 解密
  22. // if (!string.IsNullOrWhiteSpace(str))
  23. // return SM2Util.Decrypt(str);
  24. }
  25. catch
  26. {
  27. return "";
  28. }
  29. return "";
  30. }
  31. /// <summary>
  32. /// SM2加密
  33. /// </summary>
  34. /// <param name="str">明文</param>
  35. /// <returns>密文</returns>
  36. public static string Sm2Encrypt(string str)
  37. {
  38. try
  39. {
  40. // 加密
  41. if (!string.IsNullOrWhiteSpace(str))
  42. return SM2Util.Encrypt(str);
  43. }
  44. catch
  45. {
  46. return "";
  47. }
  48. return "";
  49. }
  50. #endregion SM2
  51. #region Sm4
  52. /// <summary>
  53. /// SM4解密
  54. /// </summary>
  55. /// <param name="str">密文</param>
  56. /// <returns>明文</returns>
  57. public static string Sm4Decrypt(string str)
  58. {
  59. if (!string.IsNullOrWhiteSpace(str))// 解密
  60. return SM4Util.Decrypt(new SM4Util { Data = str });
  61. return "";
  62. }
  63. /// <summary>
  64. /// SM4加密
  65. /// </summary>
  66. /// <param name="str">明文</param>
  67. /// <returns>密文</returns>
  68. public static string Sm4Encrypt(string str)
  69. {
  70. if (!string.IsNullOrWhiteSpace(str))// 加密
  71. return SM4Util.Encrypt(new SM4Util { Data = str });
  72. return "";
  73. }
  74. #endregion Sm4
  75. }