优化:加解密长度为0的字符串和bytes时直接返回长度为0的值

before-split
walon 2025-05-26 20:03:09 +08:00
parent b51893d154
commit fcbf77bb40
1 changed files with 12 additions and 0 deletions

View File

@ -148,6 +148,10 @@ namespace Obfuz
public unsafe virtual byte[] Decrypt(byte[] value, int offset, int length, int ops, int salt)
{
if (length == 0)
{
return Array.Empty<byte>();
}
var decryptedBytes = new byte[length];
int intArrLength = length >> 2;
@ -202,12 +206,20 @@ namespace Obfuz
public virtual byte[] Encrypt(string value, int ops, int salt)
{
if (value.Length == 0)
{
return Array.Empty<byte>();
}
byte[] bytes = Encoding.UTF8.GetBytes(value);
return Encrypt(bytes, 0, bytes.Length, ops, salt);
}
public virtual string DecryptString(byte[] value, int offset, int length, int ops, int salt)
{
if (length == 0)
{
return string.Empty;
}
byte[] bytes = Decrypt(value, offset, length, ops, salt);
return Encoding.UTF8.GetString(bytes);
}