From 0cd3b4b9c9442f16558a28348f5a268ec5799a71 Mon Sep 17 00:00:00 2001 From: Lex Li Date: Tue, 31 Oct 2023 13:57:53 -0400 Subject: [PATCH] Fixed #185 by removing extra paddings. --- SharpSnmpLib/Security/AESPrivacyProviderBase.cs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/SharpSnmpLib/Security/AESPrivacyProviderBase.cs b/SharpSnmpLib/Security/AESPrivacyProviderBase.cs index 234445a9..f213a23e 100644 --- a/SharpSnmpLib/Security/AESPrivacyProviderBase.cs +++ b/SharpSnmpLib/Security/AESPrivacyProviderBase.cs @@ -402,19 +402,6 @@ public ISnmpData Encrypt(ISnmpData data, SecurityParameters parameters) var pkey = PasswordToKey(_phrase.GetRaw(), parameters.EngineId.GetRaw()); var bytes = data.ToBytes(); - var reminder = bytes.Length % 8; - var count = reminder == 0 ? 0 : 8 - reminder; - using (var stream = new MemoryStream()) - { - stream.Write(bytes, 0, bytes.Length); - for (var i = 0; i < count; i++) - { - stream.WriteByte(1); - } - - bytes = stream.ToArray(); - } - var encrypted = Encrypt(bytes, pkey, parameters.EngineBoots!.ToInt32(), parameters.EngineTime!.ToInt32(), parameters.PrivacyParameters!.GetRaw()); return new OctetString(encrypted); } @@ -509,7 +496,7 @@ internal byte[] ExtendShortKey(byte[] shortKey, byte[] engineId, IAuthentication else { Array.Copy(tmpBuf, 0, extKey, keyLen, MinimumKeyLength - keyLen); - keyLen += (MinimumKeyLength - keyLen); + keyLen += MinimumKeyLength - keyLen; } lastKeyBuf = new byte[tmpBuf.Length];