26 lines
934 B
Plaintext
26 lines
934 B
Plaintext
PRINT FNsha256("Rosetta code")
|
|
END
|
|
|
|
DEF FNsha256(message$)
|
|
LOCAL buflen%, buffer%, hcont%, hprov%, hhash%, hash$, i%
|
|
CALG_SHA_256 = &800C
|
|
HP_HASHVAL = 2
|
|
CRYPT_NEWKEYSET = 8
|
|
PROV_RSA_AES = 24
|
|
buflen% = 128
|
|
DIM buffer% LOCAL buflen%-1
|
|
SYS "CryptAcquireContext", ^hcont%, 0, \
|
|
\ "Microsoft Enhanced RSA and AES Cryptographic Provider", \
|
|
\ PROV_RSA_AES, CRYPT_NEWKEYSET
|
|
SYS "CryptAcquireContext", ^hprov%, 0, 0, PROV_RSA_AES, 0
|
|
SYS "CryptCreateHash", hprov%, CALG_SHA_256, 0, 0, ^hhash%
|
|
SYS "CryptHashData", hhash%, message$, LEN(message$), 0
|
|
SYS "CryptGetHashParam", hhash%, HP_HASHVAL, buffer%, ^buflen%, 0
|
|
SYS "CryptDestroyHash", hhash%
|
|
SYS "CryptReleaseContext", hprov%
|
|
SYS "CryptReleaseContext", hcont%
|
|
FOR i% = 0 TO buflen%-1
|
|
hash$ += RIGHT$("0" + STR$~buffer%?i%, 2)
|
|
NEXT
|
|
= hash$
|