平安校园
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.

CryptogramUtil.cs 1.8 KiB

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