Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^4: Stumped by Crypt::OpenPGP::Signature->key_id

by mhi (Friar)
on Nov 22, 2011 at 12:14 UTC ( #939445=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Stumped by Crypt::OpenPGP::Signature->key_id
in thread Stumped by Crypt::OpenPGP::Signature->key_id

 unpack('H*', $sigobj->key_id) gives me a 16-digit hex number in which I can find no similarity with the Key-ID of the actual key.


Comment on Re^4: Stumped by Crypt::OpenPGP::Signature->key_id
Download Code
Re^5: Stumped by Crypt::OpenPGP::Signature->key_id
by Anonymous Monk on Nov 22, 2011 at 13:08 UTC

    Now I remember why I linked Crypt OpenPGP Brain twister, its a Short, Self Contained, Correct Example, in otherwords, more effective :)

    If you modify Crypt-OpenPGP-1.06\t\12-sign.t at the first verify call, you can see that this is to be expected

    my( $signer , $sigobj ) = $pgp->verify( Signature => $sig ); use DDS; die Dump( [ $key_id , $sigobj->key_id, unpack('H*', $sigo +bj->key_id ) , pack('H*',$key_id) ] );

    $ARRAY1 = [ '39F560A90D7F1559', "9\365`\251\r\177\25Y", '39f560a90d7f1559', "9\365`\251\r\177\25Y" ];

    I don't know if keyid is supposed to be 8 or 10 or 16, but the round trip with pack seems to work , so key_id is correct, and the hex representation is correct

    AFAIK printf would actually try to convert it, which might overflow as in

    $ perl -le " print 0x39f560a90d7f1559 Integer overflow in hexadecimal number at -e line 1. 4.17635050864817e+018

    Maybe this is the private key, and you're looking for the public key? Maybe it depends on algorithm? :)

      Thank you! A combo of your posts and some further reading on key id formats did it:

      http://search.cpan.org/grep?cpanid=BTROTT&release=Crypt-OpenPGP-1.06&string=key_id_hex&i=1&n=1&C=0 shows that your upack-suggestion is indeed just what is needed:

      lib/Crypt/OpenPGP/Certificate.pm 106:sub key_id_hex { uc unpack 'H*', $_[0]->key_id }

      I just didn't recognize the result since I was expecting the short key ID format and that outputs the long format.

      The solution is:

      print "KeyID hex long: 0x", uc unpack('H*', $sigobj->key_id) + ,"\n"; print "KeyID hex short: 0x",uc substr( unpack('H*', $sigobj->key_id), +-8, 8),"\n";

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (16)
As of 2015-07-06 14:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (75 votes), past polls