Hi ghosttie,
Thanks for getting back to me so quickly; it's most appreciated
. In regards to your help, I have already coded everything that you have entered, it was just that I was getting an error when it came to using the cryptCreateHash method. The only difference that I could find between what I have done and what you have illustrated, is that I have used cryptHashData rather than cryptHashDataString. Even though I am trying to hash a string, does it matter which method I use?
Here's what I have:
Code: Select all
/*
* Connect to Cryptographic Service Provider (CSP) and return a handle to it
* If you cannot connect to an existing key container with this name,
* Try to create a key container with a default name
*/
str_pszProvider := MS_DEF_PROV;
int_acquireContext := call cryptAcquireContext(int_phProv,str_pszContainer,str_pszProvider,PROV_RSA_FULL,Gc_0);
if (int_acquireContext = Gc_0) then
int_acquireContext := call cryptAcquireContext(int_phProv,str_pszContainer,str_pszProvider,PROV_RSA_FULL,CRYPT_NEWKEYSET);
if (int_acquireContext = Gc_0) then
write "cryptAcquireContext Error : Container unavailable; Handle not created";
return false;
endif;
endif;
/*
* Initiate the hashing function
*/
int_createHash := call cryptCreateHash(int_phProv,CALG_SHA_256,Gc_0,Gc_0,int_phHash);
if (int_createHash = Gc_0) then
write "cryptCreateHash Error : Unable to initiate the hashing function";
return false;
endif;
/*
* Hash the data
*/
int_hashData := call cryptHashData(int_phHash,str_toHash,str_toHash.length,Gc_0);
if (int_hashData = Gc_0) then
write "cryptHashData Error : Unable to hash the data";
return false;
endif;
/*
* Retrieve the data that runs the operations of a hash object
*/
int_toHashLen := str_toHash.length;
int_getHash := call cryptGetHashParam(int_phHash,HP_HASHVAL,str_toHash,int_toHashLen,Gc_0);
if (int_getHash = Gc_0) then
write "cryptGetHashParam Error : Unable to retrieve data";
return false;
endif;
str_hashOutput := str_toHash[1:int_toHashLen];
bin_hashBinary := str_hashOutput.Binary;
/*
* Destroy the hash object
*/
call cryptDestroyHash(int_phHash);
/*
* Release the CSP handle
*/
call cryptReleaseContext(int_phProv, Gc_0);
When I ran this (alongside some other coding specific to my use, which was just collecting data and putting it into a String), I seemed to have got the error in regards to the cryptCreateHash method. I'm not sure if it's because of the way I have defined the SHA-256 Algorithm:
Code: Select all
constants
CALG_SHA_256 : Integer = #800C; // I'm not sure whether the #800C is right. I think it's meant to be the Integer value of the SHA hex representation of 0x000800c
HP_HASHVAL : Integer = Gc_2;
PROV_RSA_FULL : Integer = Gc_1;
CRYPT_NEWKEYSET : Integer = Gc_8;
MS_DEF_PROV : String = "Microsoft Base Cryptographic Provider v1.0";
Any opinions?
Thanks,
Omash