Browse Source

Merge pull request #1089 from colinin/sm4-encryption

🐛 fix(encryption): InitVectorBytes Configuration values should beused
pull/1091/head
yx lin 1 year ago
committed by GitHub
parent
commit
1b7ec6162e
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      aspnet-core/framework/security/LINGYUN.Abp.Encryption.SM4/LINGYUN/Abp/Encryption/SM4/SM4StringEncryptionService.cs

6
aspnet-core/framework/security/LINGYUN.Abp.Encryption.SM4/LINGYUN/Abp/Encryption/SM4/SM4StringEncryptionService.cs

@ -37,10 +37,9 @@ public class SM4StringEncryptionService : StringEncryptionService
using var password = new Rfc2898DeriveBytes(passPhrase, salt); using var password = new Rfc2898DeriveBytes(passPhrase, salt);
// 128-bit key // 128-bit key
var keyBytes = password.GetBytes(16); var keyBytes = password.GetBytes(16);
var ivBytes = password.GetBytes(16);
var cipher = new PaddedBufferedBlockCipher(new CbcBlockCipher(new SM4Engine()), new Pkcs7Padding()); var cipher = new PaddedBufferedBlockCipher(new CbcBlockCipher(new SM4Engine()), new Pkcs7Padding());
cipher.Init(false, new ParametersWithIV(new KeyParameter(keyBytes), ivBytes)); cipher.Init(false, new ParametersWithIV(new KeyParameter(keyBytes), Options.InitVectorBytes));
var decryptTextBytes = cipher.DoFinal(cipherTextBytes); var decryptTextBytes = cipher.DoFinal(cipherTextBytes);
@ -61,10 +60,9 @@ public class SM4StringEncryptionService : StringEncryptionService
using var password = new Rfc2898DeriveBytes(passPhrase, salt); using var password = new Rfc2898DeriveBytes(passPhrase, salt);
// 128-bit key // 128-bit key
var keyBytes = password.GetBytes(16); var keyBytes = password.GetBytes(16);
var ivBytes = password.GetBytes(16);
var cipher = new PaddedBufferedBlockCipher(new CbcBlockCipher(new SM4Engine()), new Pkcs7Padding()); var cipher = new PaddedBufferedBlockCipher(new CbcBlockCipher(new SM4Engine()), new Pkcs7Padding());
cipher.Init(true, new ParametersWithIV(new KeyParameter(keyBytes), ivBytes)); cipher.Init(true, new ParametersWithIV(new KeyParameter(keyBytes), Options.InitVectorBytes));
var decryptTextBytes = cipher.DoFinal(plainTextBytes); var decryptTextBytes = cipher.DoFinal(plainTextBytes);

Loading…
Cancel
Save