https://forums.jadeworld.com/viewtopic.php?f=9&t=1256 and https://forums.jadeworld.com/viewtopic.php?f=11&t=594.
However I'm stuck on trying to get the hash value back using the CryptGetHashParam method. I've looked at the MSDN documentation for the method and example programs, however they are written in C and involve calling the method twice to set memory space up and then retrieving the actual value which I'm not sure is necessary in Jade as well.
The relevant external functions I have are
Code: Select all
cryptGetHashParam(hHash : Integer;dwParam: Integer; pbData : Binary;pdwDataLen : Integer io;dwFlags : Integer):Integer is CryptGetHashParam in advapi32 applicationServerExecution;
cryptAcquireContext(phProv : Integer io;pszContainer : String;pszProvider : String;dwProvType : Integer;dwFlags : Integer) : Integer is CryptAcquireContextA in advapi32 applicationServerExecution;
cryptCreateHash(hProv : Integer;algid : Integer;hKey : Integer;dwFlags : Integer;phHash : Integer io) : Integer is CryptCreateHash in advapi32 applicationServerExecution;
cryptHashData(hHash : Integer;pbData : String;dwDataLen : Integer;dwFlags : Integer) : Integer is CryptHashData in advapi32 applicationServerExecution;
cryptDestroyHash(hHash : Integer): Integer is CryptDestroyHash in advapi32 applicationServerExecution;
cryptReleaseContext(hProv : Integer;dwFlags : Integer) : Integer is CryptReleaseContext in advapi32 applicationServerExecution;
Code: Select all
constants
MS_DEF_PROV : String = "Microsoft Base Cryptographic Provider v1.0";
MS_ENHANCED_PROV : String = "Microsoft Enhanced Cryptographic Provider";
MS_STRONG_PROV : String = "Microsoft Strong Cryptographic Provider";
PROV_RSA_FULL : Integer = 1;
CRYPT_NEWKEYSET : Integer = 8;
CALG_MD5 : Integer = 32771; //ALG_CLASS_HASH.bitOr(ALG_TYPE_ANY).bitOr(ALG_SID_MD5)
Key_Length : Integer = 8388608; // 128bit - 0x00800000
vars
message: String;
hProv : Integer;
hHash : Integer;
hKey : Integer;
tmpBinary: Binary;
tmpLength : Integer;
container: String;
begin
message := "Message Body to generate a MD5 hash for";
container := 'Container';
// connect to CSP
if call cryptAcquireContext(hProv, container, MS_STRONG_PROV, PROV_RSA_FULL, 0) = 0 then
if call cryptAcquireContext(hProv, container, MS_STRONG_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET) = 0 then
write "Error during CryptAcquireContext for a new key container.";
endif;
endif;
// create a hash object
if call cryptCreateHash(hProv, CALG_MD5, 0, 0, hHash) = 0 then
write "Error during CryptCreateHash";
endif;
// hash the message
if call cryptHashData(hHash, message, message.length, 0) = 0 then
write "Error during CryptHashData";
endif;
//call cryptGetHashParam(hHash, 4, null, tmpLength, 0); //4 is constant for getting hash size
call cryptGetHashParam(hHash, 2, tmpBinary, tmpLength, 0); //2 is constant for getting hash value
write tmpLength;
write tmpBinary.String;
epilog
// destroy hash object
if hHash <> 0 then
call cryptDestroyHash(hHash);
endif;
// disconnect from CSP
if hProv <> 0 then
call cryptReleaseContext(hProv, 0);
endif;
end;
Is anyone able to provide further information around how to use this method please.
Thanks.