For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

quangtran's avatar
quangtran
Icon for Cirrus rankCirrus
Feb 01, 2023
Solved

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. ...
  • JRahm's avatar
    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: