Back to Four Js Website
Four Js Customer Forum
Subscribe for automatic updates:
RSS
Sign in for full access
|
Help
Four Js Development Tools Forum
>
Discussions by product
>
Genero BDL
>
HMAC hash key
Most recent posts
Pages: [
1
]
« previous
next »
Reply
|
Print
Author
Topic: HMAC hash key (Read 539 times)
Evandro S.
Posts: 5
HMAC hash key
«
on:
March 21, 2025, 09:01:45 pm »
Hello guys,
I'm in need of getting hmac hash keys to access AWS services via API.
In JS, i can get hmac hash using the following command:
crypto.createHmac('sha256', `mykey`).update("myadditionalvalue").digest('hex');
But i need it working on a 4gl program. In the documentation isn't that clear how to get the same cenario like the command above using xml.Crypto class.
Any help would be great.
Thanks
Daniele A.
Posts: 29
Re: HMAC hash key
«
Reply #1 on:
March 27, 2025, 11:06:09 am »
Hello Evandro,
i think this example can fits your needs:
function bdl_hmac_hash(prm_algo string, prm_data string, prm_key string) returns (string)
define ckey xml.CryptoKey,
sig xml.Signature,
ialgo smallint,
signature string
define ar_algo_supported dynamic array of record
algcode string,
link string
end record =
[
( algcode: 'HmacSHA1', link: '
http://www.w3.org/2000/09/xmldsig#hmac-sha1
' ),
( algcode: 'HmacSHA256',link: '
http://www.w3.org/2001/04/xmldsig-more#hmac-sha256
'),
( algcode: 'HmacSHA384',link: '
http://www.w3.org/2001/04/xmldsig-more#hmac-sha384
'),
( algcode: 'HmacSHA512',link: '
http://www.w3.org/2001/04/xmldsig-more#hmac-sha512
')
]
let prm_algo = prm_algo.trim()
if prm_algo.getLength()=0 then
let prm_algo = 'HmacSHA256'
end if
let ialgo = ar_algo_supported.search("algcode",prm_algo)
if ialgo>0 then
let ckey = xml.CryptoKey.Create(ar_algo_supported[ialgo].link)
try
call ckey.setKey(prm_key)
#display "Key url : ",ckey.getUrl()
#display "Key size (in bits) : ",ckey.getSize()
#display "Key type : ",ckey.getType() # displays HMAC
#display "Key usage : ",ckey.getUsage() # displays SIGNATURE
catch
display "Unable to set key :",STATUS," - ",SQLCA.SQLERRM
end try
-- Create the signature
let sig = xml.Signature.Create()
call sig.setKey(ckey)
let signature = xml.Signature.signString(ckey,prm_data)
display iif(xml.Signature.verifyString(ckey,prm_data,signature), "success","failure")
end if
return signature
end function
Daniele
Pages: [
1
]
Reply
|
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> General Discussion
=> Ask Reuben
=> WWDC21
-----------------------------
Discussions by product
-----------------------------
=> Products announcements
=> Genero BDL
=> GWS
=> GAS and GBC
=> GDC
=> Genero Mobile for Android or iOS
=> Genero Studio
=> Reporting tools (GRW, GRE)
-----------------------------
Jobs
-----------------------------
=> Jobs
Powered by SMF 1.1.21
|
SMF © 2015, Simple Machines
Loading...