// Admin.NET 项目的版æƒã€å•†æ ‡ã€ä¸“利和其他相关æƒåˆ©å‡å—ç›¸åº”æ³•å¾‹æ³•è§„çš„ä¿æŠ¤ã€‚ä½¿ç”¨æœ¬é¡¹ç›®åº”éµå®ˆç›¸å…³æ³•律法规和许å¯è¯çš„è¦æ±‚。 // // 本项目主è¦éµå¾ª MIT 许å¯è¯å’Œ Apache 许å¯è¯ï¼ˆç‰ˆæœ¬ 2.0)进行分å‘和使用。许å¯è¯ä½äºŽæºä»£ç æ ‘æ ¹ç›®å½•ä¸çš„ LICENSE-MIT å’Œ LICENSE-APACHE 文件。 // // ä¸å¾—利用本项目从事å±å®³å›½å®¶å®‰å…¨ã€æ‰°ä¹±ç¤¾ä¼šç§©åºã€ä¾µçŠ¯ä»–äººåˆæ³•æƒç›Šç‰æ³•å¾‹æ³•è§„ç¦æ¢çš„æ´»åЍï¼ä»»ä½•基于本项目二次开å‘è€Œäº§ç”Ÿçš„ä¸€åˆ‡æ³•å¾‹çº çº·å’Œè´£ä»»ï¼Œæˆ‘ä»¬ä¸æ‰¿æ‹…ä»»ä½•è´£ä»»ï¼ namespace Admin.NET.Core; public class CryptogramUtil { public static readonly bool StrongPassword = App.GetConfig<bool>("Cryptogram:StrongPassword"); // 是å¦å¼€å¯å¯†ç å¼ºåº¦éªŒè¯ public static readonly string PasswordStrengthValidation = App.GetConfig<string>("Cryptogram:PasswordStrengthValidation"); // 密ç å¼ºåº¦éªŒè¯æ£åˆ™è¡¨è¾¾å¼ public static readonly string PasswordStrengthValidationMsg = App.GetConfig<string>("Cryptogram:PasswordStrengthValidationMsg"); // 密ç å¼ºåº¦éªŒè¯æç¤º public static readonly string CryptoType = App.GetConfig<string>("Cryptogram:CryptoType"); // åŠ å¯†ç±»åž‹ public static readonly string PublicKey = App.GetConfig<string>("Cryptogram:PublicKey"); // 公钥 public static readonly string PrivateKey = App.GetConfig<string>("Cryptogram:PrivateKey"); // ç§é’¥ public static readonly string SM4_key = "0123456789abcdeffedcba9876543210"; public static readonly string SM4_iv = "595298c7c6fd271f0402f804c33d3f66"; /// <summary> /// åŠ å¯† /// </summary> /// <param name="plainText"></param> /// <returns></returns> public static string Encrypt(string plainText) { if (CryptoType == CryptogramEnum.MD5.ToString()) { return MD5Encryption.Encrypt(plainText); } else if (CryptoType == CryptogramEnum.SM2.ToString()) { return SM2Encrypt(plainText); } else if (CryptoType == CryptogramEnum.SM4.ToString()) { return SM4EncryptECB(plainText); } return plainText; } /// <summary> /// 解密 /// </summary> /// <param name="cipherText"></param> /// <returns></returns> public static string Decrypt(string cipherText) { if (CryptoType == CryptogramEnum.SM2.ToString()) { return SM2Decrypt(cipherText); } else if (CryptoType == CryptogramEnum.SM4.ToString()) { return SM4DecryptECB(cipherText); } return cipherText; } /// <summary> /// SM2åŠ å¯† /// </summary> /// <param name="plainText"></param> /// <returns></returns> public static string SM2Encrypt(string plainText) { return GMUtil.SM2Encrypt(PublicKey, plainText); } /// <summary> /// SM2解密 /// </summary> /// <param name="cipherText"></param> /// <returns></returns> public static string SM2Decrypt(string cipherText) { return GMUtil.SM2Decrypt(PrivateKey, cipherText); } /// <summary> /// SM4åŠ å¯†ï¼ˆECB) /// </summary> /// <param name="plainText"></param> /// <returns></returns> public static string SM4EncryptECB(string plainText) { return GMUtil.SM4EncryptECB(SM4_key, plainText); } /// <summary> /// SM4解密(ECB) /// </summary> /// <param name="cipherText"></param> /// <returns></returns> public static string SM4DecryptECB(string cipherText) { return GMUtil.SM4DecryptECB(SM4_key, cipherText); } /// <summary> /// SM4åŠ å¯†ï¼ˆCBC) /// </summary> /// <param name="plainText"></param> /// <returns></returns> public static string SM4EncryptCBC(string plainText) { return GMUtil.SM4EncryptCBC(SM4_key, SM4_iv, plainText); } /// <summary> /// SM4解密(CBC) /// </summary> /// <param name="cipherText"></param> /// <returns></returns> public static string SM4DecryptCBC(string cipherText) { return GMUtil.SM4DecryptCBC(SM4_key, SM4_iv, cipherText); } }