NopCommerce 定制系列(一):增加 Sha256+Base64 加密

一、Nop.Core.Domain.Customers.PasswordFormat ( enum  ),增加一个 “S256_B64”。

二、Libraries\Nop.Services\Security\EncryptionService.cs 及其接口增加对应方法

   1: #region
   2: /// <param name="str">string str:被加密的字符串</param>
   3: /// <returns>返回加密后的字符串</returns>
   4: public virtual string S256_B64Encrypt(string str)
   5: {
   6:     System.Security.Cryptography.SHA256 s256 = new System.Security.Cryptography.SHA256Managed();
   7:  
   8:     byte[] byte1;
   9:     byte1 = s256.ComputeHash(Encoding.Default.GetBytes(str));
  10:     s256.Clear();
  11:  
  12:     return Convert.ToBase64String(byte1);
  13: }
  14: #endregion

三、增加对 “S256_B64”的支持,code中有若干处。

   1: switch (customer.PasswordFormat)
   2:                 {
   3:                     case PasswordFormat.Encrypted:
   4:                         oldPwd = _encryptionService.EncryptText(request.OldPassword);
   5:                         break;
   6:                     case PasswordFormat.Hashed:
   7:                         oldPwd = _encryptionService.CreatePasswordHash(request.OldPassword, customer.PasswordSalt, _customerSettings.HashedPasswordFormat);
   8:                         break;
   9:                     #region     这里增加对  “S256_B64”的支持,code中有若干处。
  10:                     case PasswordFormat.S256_B64:
  11:                         oldPwd = _encryptionService.S256_B64Encrypt(request.OldPassword);
  12:                         break;
  13:                     #endregion
  14:                     default:
  15:                         oldPwd = request.OldPassword;
  16:                         break;
  17:                 }

四、广谱搜索关键字“PasswordFormat.Hashed”,将其改成想用的加密方法即可。

你可能感兴趣的:(base64)