MD5 implementation query on API gateway
search cancel

MD5 implementation query on API gateway

book

Article ID: 281735

calendar_today

Updated On: 08-08-2024

Products

CA API Gateway

Issue/Introduction

We have an issue with the current way the MD5 sum is calculated in the "Generate Security Hash Assertion"

Generate Security Hash Assertion (broadcom.com)

For our automation, we need to programmatically generate md5sums via bash script which would match the md5sum in some assertion. Our requirement is that it would match the simple md5sum function available on any Linux distribution:

Expected:

$ echo "fred" | md5sum
08b622ddf7eb7c8e44cdb3bd6362f966  -

 

Actual:

Source data: ${var}
Value of context variable named "var":  a String type: "fred"
Input characters: 4 characters: { f, r, e, d }
Chars converted to bytes using UTF-8:  4 bytes: { 66, 72, 65, 64 }
MD5 hash of these 4 bytes: 16 bytes: { 57, 0a, 90, bf, bf, 8c, 7e, ab, 5d, c5, d4, e2, 68, 32, d5, b1 }
Base-64 encoding of MD5 hash 16 bytes: "VwqQv7+MfqtdxdTiaDLVsQ=="

Environment

All supported API gateways

Resolution

Check TechDocs:
 
To obtain a hex encoded version of the value, use the Encode/Decode Data Assertion to Base64-decode it to Message data type, then Base16-encode it to String.
 
If they use echo command, they should add -n option to avoid adding line break to the data.
% echo -n "fred" | md5 570a90bfbf8c7eab5dc5d4e26832d5b1
Base-64 encoding of MD5 hash 16 bytes: "VwqQv7+MfqtdxdTiaDLVsQ=="
This is Base64 encoding of MD5 digest 16 bytes (binary array).
$ echo -n "fred" | md5sum | base64
md5sum produces "570a90bfbf8c7eab5dc5d4e26832d5b1\n" string which is 33 bytes long in ASCII or UTF-8 encoding.