Forum Discussion
quangtran
Feb 01, 2023Cirrus
What is the output of crypto::hash
I have a piece of irule code: when HTTP_REQUEST_DATA { set data [findstr [HTTP::payload] "Data" 9 \" ] log local0. "raw data = $data" set hash_data [CRYPTO::hash -alg sha256 $data ] log local0. ...
- Feb 02, 2023
Hi quangtran, you need to represent the binary string as a string of hex digits in your code:
when RULE_INIT { set data "hello, world" log local0. "raw data = $data" set hash_data [CRYPTO::hash -alg sha256 $data ] log local0. "hashing data = $hash_data" binary scan $hash_data H* hash_data_hex log local0. "hashing data as string = $hash_data_hex" }
This results in my log file as:
Feb 2 17:51:16 ltm3.test.local info tmm[115055]: Rule /Common/hash_example <RULE_INIT>: raw data = hello, world Feb 2 17:51:16 ltm3.test.local info tmm[115055]: Rule /Common/hash_example <RULE_INIT>: hashing data = Ê~NªnéÇÒaq)HdMߺ|¿¼L6 [ Feb 2 17:51:16 ltm3.test.local info tmm[115055]: Rule /Common/hash_example <RULE_INIT>: hashing data as string = 09ca7e4eaa6e8ae9c7d261167129184883644d07dfba7cbfbc4c8a2e08360d5b
And you can see that that string matches the online generated hash as well:
JRahm
Feb 02, 2023Admin
Hi quangtran, you need to represent the binary string as a string of hex digits in your code:
when RULE_INIT {
set data "hello, world"
log local0. "raw data = $data"
set hash_data [CRYPTO::hash -alg sha256 $data ]
log local0. "hashing data = $hash_data"
binary scan $hash_data H* hash_data_hex
log local0. "hashing data as string = $hash_data_hex"
}
This results in my log file as:
Feb 2 17:51:16 ltm3.test.local info tmm[115055]: Rule /Common/hash_example <RULE_INIT>: raw data = hello, world
Feb 2 17:51:16 ltm3.test.local info tmm[115055]: Rule /Common/hash_example <RULE_INIT>: hashing data = Ê~NªnéÇÒaq)HdMߺ|¿¼L6 [
Feb 2 17:51:16 ltm3.test.local info tmm[115055]: Rule /Common/hash_example <RULE_INIT>: hashing data as string = 09ca7e4eaa6e8ae9c7d261167129184883644d07dfba7cbfbc4c8a2e08360d5b
And you can see that that string matches the online generated hash as well:
- quangtranFeb 03, 2023Cirrus
this is exactly what I needed. Many thanks!
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects