Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^2: Signed Long Hash

by breezykatt (Acolyte)
on Jun 15, 2017 at 17:25 UTC ( #1192882=note: print w/replies, xml ) Need Help??

in reply to Re: Signed Long Hash
in thread Signed Long Hash

One follow up question - how does one convert a numeric value (eg -281581062704388899) to base64 in perl similar to java's call:


to get the java base64 encoded string: '/Befg+4HJN0'

Replies are listed 'Best First'.
Re^3: Signed Long Hash
by hippo (Chancellor) on Jun 15, 2017 at 17:45 UTC

    See MIME::Base64 and perhaps pack.

    Update: Although I do not receive the same result - are you sure about the input and output?

    use strict; use warnings; use MIME::Base64 'encode_base64'; use Test::More tests => 1; is (encode_base64((pack 'q', -281581062704388899), ''), '/Befg+4HJN0') +;

    gives '3SQH7oOfF/w=' instead.

      Thanks. What I was trying to do was something similar, but this might not yield the same results to what i'm trying to achieve? I thought I had to convert the value to an array of bytes first and then convert that to base64. Something like:

      $signed="-281581062704388899"; $bits = unpack("B*", pack("N", $signed)); $base64 = encode_base64(pack("B*", $bits), ""); #or $base64 = encode_base64($bits);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1192882]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2020-08-12 21:16 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (68 votes). Check out past polls.