correctly detect encrypted string encoding when decrypting #313

This commit is contained in:
Eliot Jones 2021-04-30 10:22:50 -04:00
parent c2f2916c04
commit c7c4adf441

View File

@ -402,7 +402,7 @@
var decrypted = DecryptData(data, reference);
token = new StringToken(OtherEncodings.BytesAsLatin1String(decrypted));
token = GetStringTokenFromDecryptedData(decrypted);
break;
}
@ -465,6 +465,25 @@
return token;
}
private static StringToken GetStringTokenFromDecryptedData(byte[] data)
{
if (data[0] == 0xFE && data[1] == 0xFF)
{
var str = Encoding.BigEndianUnicode.GetString(data).Substring(1);
return new StringToken(str, StringToken.Encoding.Utf16BE);
}
if (data[0] == 0xFF && data[1] == 0xFE)
{
var str = Encoding.Unicode.GetString(data).Substring(1);
return new StringToken(str, StringToken.Encoding.Utf16);
}
return new StringToken(OtherEncodings.BytesAsLatin1String(data), StringToken.Encoding.Iso88591);
}
private byte[] DecryptData(byte[] data, IndirectReference reference)
{
if (useAes && encryptionKey.Length == 32)