Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
sha256
#1
Get QM to HASH sha256?

Thanks!
#2
Member function str.HashSHA256
Code:
Copy      Help
function$ !*buffer bufferSize [flags] ;;flags: 1 Hex (0 binary)

;Compute SHA256 checksum for input buffer.
;Returns self.
;Error if fails.

;buffer - input buffer. Can be a string or other memory.
;bufferSize - input buffer size. If <0, calculates length of buffer string.

;REMARKS
;From <link>http://nagareshwar.securityxploded.com/2010/10/22/cryptocode-generate-sha1sha256-hash-using-windows-cryptography-library/</link>.

;EXAMPLE
;str s
;s.HashSHA256("The quick brown fox jumps over the lazy dog" -1 1)
;out s


;ref WINAPI2
dll advapi32 [CryptAcquireContextA]#CryptAcquireContext *phProv $szContainer $szProvider dwProvType dwFlags
def CRYPT_VERIFYCONTEXT 0xF0000000
def PROV_RSA_AES 24
dll advapi32 #CryptCreateHash hProv Algid hKey dwFlags *phHash
dll advapi32 #CryptHashData hHash !*pbData dwDataLen dwFlags
dll advapi32 #CryptGetHashParam hHash dwParam !*pbData *pdwDataLen dwFlags
def HP_HASHSIZE 0x0004
def HP_HASHVAL 0x0002
dll advapi32 #CryptDestroyHash hHash
dll advapi32 #CryptReleaseContext hProv dwFlags
def CALG_SHA256 0x0000800C

int dwStatus bResult hProv hHash cbHashSize
if(bufferSize<0) lpstr _k=buffer; bufferSize=len(_k)

if(!CryptAcquireContext(&hProv, 0, 0, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) ret
if(!CryptCreateHash(hProv, CALG_SHA256, 0, 0, &hHash)) goto EndHash
if(!CryptHashData(hHash, buffer, bufferSize, 0)) goto EndHash
int dwCount = sizeof(int);
if(!CryptGetHashParam(hHash, HP_HASHSIZE, &cbHashSize, &dwCount, 0)) goto EndHash
this.all(cbHashSize 2)
if(!CryptGetHashParam(hHash, HP_HASHVAL, this, &cbHashSize, 0)) goto EndHash
bResult = 1;
;EndHash
if(hHash) CryptDestroyHash(hHash);
if(hProv) CryptReleaseContext(hProv, 0);
if(!bResult) end F"{ERR_FAILED}. {_s.dllerror}"

if(flags&1) this.encrypt(8)
Tested only on Windows 7, but should work on XP SP3. Not on XP SP2 or older.
#3
SHA256withRSA?

Trying to work out this with QM: https://developers.google.com/accounts/ ... iceAccount

Just about there, but of course I don't know SHA256withRSA

-Jim
#4
In case it matters, the private key file is you get from google is a "p12" file extension. (Edit: figured out how to make a PEM private key file using openSSL)

"Sign the UTF-8 representation of the input using SHA256withRSA (also known as RSASSA-PKCS1-V1_5-SIGN with the SHA-256 hash function) with the private key obtained from the Google Cloud Console"

-Jim
#5
Trying to use OpenSSl but get error that data is too large for key size.

I really really hope to get some help on this!


Forum Jump:


Users browsing this thread: 1 Guest(s)