Look at this code:
SetLength(Result, cbSignedBlob);
system.Move(signature^, Pointer(Result)^, cbSignedBlob);
I'm just guessing, but Result
is probably of type string
. That's a UTF-16 encoded string. But you copy in just cbSignedBlob
bytes, which fills only half of the buffer. I suspect that you have either ANSI or UTF-8 encoded text, but it is a little hard to tell.
If the text is UTF-8 encoded, then this is what you do:
var
utf8: UTF8String;
....
SetLength(utf8, cbSignedBlob);
system.Move(signature^, Pointer(utf8)^, cbSignedBlob);
Result := string(utf8);
If the text is ANSI encoded then you would do this:
var
ansi: AnsiString(1252); // or whatever the code page really is
....
SetLength(ansi, cbSignedBlob);
system.Move(signature^, Pointer(ansi)^, cbSignedBlob);
Result := string(ansi);
There's probably more going on here but given the amount of detail presented in the question, this is as much as I can see.
For a start I am very suspicious of your lack of error checking. You call these API functions but ignore their return values. I'll wager the functions fail and your code continues regardless. Next step is to add error checking.