Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xively Device Activation Code does not match using HMAC-SHA1 algorithm

Tags:

xively

I am trying to calculate the Activation Code from Product Secret and Device Serial Number, my calculated Activation Code is always different from Xively's.

Can someone please help me to point out where I am wrong?

From Xievely web portal:

Product ID: 4sA5tK9XF_3xKfOawmyO
Product Secret: be0f6928e3653cf175b7f8ebb2da50c6658b30b7
Serial Number: 123123123
Activation Code: 93d80b284a19d14e99d9abb7d637afc59d4b0f95

I tested with PHP:

echo hash_hmac("sha1","123123123","be0f6928e3653cf175b7f8ebb2da50c6658b30b7");

Activation code I generated is: 66b02f4c691287144c09e3b76816275742c155b5 which is different from Xively's.

Please help, thanks a million.

like image 322
leon Avatar asked Nov 09 '22 21:11

leon


1 Answers

Provided that you are using PHP 5 you can convert the secret into binary using hex2bin() and this should work. Try this:

$secret_string='be0f6928e3653cf175b7f8ebb2da50c6658b30b7';
$secret=hex2bin($secret_string);
echo hash_hmac("sha1", '123123123',$secret)."\n";

if no PHP5 you can define hex2bin yourself.

Paul

like image 187
user1712240 Avatar answered Jan 04 '23 03:01

user1712240