Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ColdFusion equivalent to PHP hash_hmac

Tags:

php

coldfusion

$key = "12345678876543211234567887654321";
$iv = "1234567887654321";
$plaindata = "This is a test string";

$enc = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $plaindata, MCRYPT_MODE_CBC, $iv));

$str = hash_hmac("sha256", utf8_encode($iv . '.' . $enc), utf8_encode($key));

echo($str);

This gives me e63d4ab83f90cfec1acdaf831091b6394167ae728b657e44afad1e7553843eeb

How can I get the same result in ColdFusion9 Development Edition?

like image 791
user812120 Avatar asked May 18 '26 06:05

user812120


1 Answers

I found a solution on this page http://www.isummation.com/blog/calculate-hmac-sha256-digest-using-user-defined-function-in-coldfusion/

Your need to call the function like this

<cfoutput>#LCase(HMAC_SHA256(iv & "." & Encrypted_Data, key))#</cfoutput>

Worked like a charm.

like image 156
user812120 Avatar answered May 19 '26 21:05

user812120



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!