mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-04-05 20:55:01 +08:00
correctly detect encrypted string encoding when decrypting #313
This commit is contained in:
parent
c2f2916c04
commit
c7c4adf441
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user