I'm trying to implement the authentication described here.
In step 7, the integer/string (it's not clear) that represents the user ID is 1. That's converted into the bytes represented by 0x00000000 00000001
(8 bytes). I'm trying to write the Perl that would do that conversion, so that those bytes can then be passed to Digest::SHA as part of the message. The doc describes this ID as "8-byte (big-endian) user identifier".
I concluded the Encode module isn't right as this should be perl internal string -> binary, without a character encoding in-between. I thought that unpack is the right way to go, but I'm not having much luck. I thought maybe I can have it represented as hex (something that Digest::SHA accepts as a data format for the message):
my $user_id_h = unpack("H*", $user_id);
results in 31. OK, that's ASCII code for the character "1". But why is unpack treating it as a string? Probably because Perl doesn't differentiate internally between strings and numbers. So can I tell Perl it's a number?
Treating it as an integer, such as
results in undefined.
I feel like there are probably some concepts I am missing here. Am I on the right lines with unpacl? How do I get from a perl number hard-coded or loaded from a config file to the big-endian binary octets that represent that number to pass to Digest::SHA? I am on (little-endian) Intel.
In this Java implementation
at line 385 the User ID is treated as a java Long
, and then the ByteBuffer
is used to just do the right thing, whatever that is.