Click here to get back home

Digest::SHA1 b64digest weirdness

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Digest::SHA1 b64digest weirdness Greg G 05-10-2005
Get Chitika Premium
Posted by Greg G on May 10, 2005, 1:33 pm
Please log in for more thread options



This is really bizzaro. Here's my code:

use Digest::SHA1;

$password = "garbage";
my $ctx = Digest::SHA1->new;
$ctx->add($password);
my $encpw = "" . $ctx->b64digest . "=";
print STDERR "" . $ctx->b64digest . "=\n";
print STDERR "$encpw\n";
print STDERR "" . ($ctx->b64digest) . "=\n";

But here's the output:

2jmj7l5rSw0yVb/vlWAYkK/YBwk=
eMZ8EmV1wgxrRoRHNV6b0g0iEgI=
2jmj7l5rSw0yVb/vlWAYkK/YBwk=


What gives here? Why are these different? Incidentally, the $encpw one
is the correct one.

Thanks.

-Greg G


Posted by Jim Gibson on May 10, 2005, 12:41 pm
Please log in for more thread options



> This is really bizzaro. Here's my code:
>
> use Digest::SHA1;
>
> $password = "garbage";
> my $ctx = Digest::SHA1->new;
> $ctx->add($password);
> my $encpw = "" . $ctx->b64digest . "=";
> print STDERR "" . $ctx->b64digest . "=\n";
> print STDERR "$encpw\n";
> print STDERR "" . ($ctx->b64digest) . "=\n";
>
> But here's the output:
>
> 2jmj7l5rSw0yVb/vlWAYkK/YBwk=
> eMZ8EmV1wgxrRoRHNV6b0g0iEgI=
> 2jmj7l5rSw0yVb/vlWAYkK/YBwk=
>
>
> What gives here? Why are these different? Incidentally, the $encpw one
> is the correct one.

Did you read the documentation for Digest::SHA1?

$sha1->digest

Note that the "digest" operation is effectively a destructive,
read-once operation. Once it has been performed, the "Digest::SHA1"
object is automatically "reset" and can be used to calculate
another digest value. Call $sha1->clone->digest if you want to
calculate the digest without reseting the digest state.

$sha1->b64digest
Same as $sha1->digest, but will return the digest as a base64
encoded string.

Print the values using $ctx->clone->b64digest and they will be the same.


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000
Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


Posted by Greg G on May 10, 2005, 5:31 pm
Please log in for more thread options


Jim Gibson wrote:
>
>
>>This is really bizzaro. Here's my code:
>>
>>use Digest::SHA1;
>>
>>$password = "garbage";
>>my $ctx = Digest::SHA1->new;
>>$ctx->add($password);
>>my $encpw = "" . $ctx->b64digest . "=";
>>print STDERR "" . $ctx->b64digest . "=\n";
>>print STDERR "$encpw\n";
>>print STDERR "" . ($ctx->b64digest) . "=\n";
>>
>>But here's the output:
>>
>>2jmj7l5rSw0yVb/vlWAYkK/YBwk=
>>eMZ8EmV1wgxrRoRHNV6b0g0iEgI=
>>2jmj7l5rSw0yVb/vlWAYkK/YBwk=
>>
>>
>>What gives here? Why are these different? Incidentally, the $encpw one
>>is the correct one.
>
>
> Did you read the documentation for Digest::SHA1?

I hadn't. That does indeed explain what I'm seeing. { D'OH! }

Thanks.


> $sha1->b64digest
> Same as $sha1->digest, but will return the digest as a base64
> encoded string.
>
> Print the values using $ctx->clone->b64digest and they will be the same.

-Greg G


Posted by Ed on May 10, 2005, 7:06 pm
Please log in for more thread options


Greg G wrote:

> This is really bizzaro. Here's my code:
>
> use Digest::SHA1;

> my $encpw = "" . $ctx->b64digest . "=";
> print STDERR "" . $ctx->b64digest . "=\n";

> What gives here? Why are these different? Incidentally, the $encpw one
> is the correct one.

perldoc Digest::SHA1

says to see also...

perldoc Digest

(Specifically, see the doc for the digest function.)

Ed


Similar ThreadsPosted
Q: Digest::SHA1 module cannot be loaded February 8, 2005, 5:50 pm
SOAP::Lite weirdness April 6, 2006, 8:07 am
weirdness with CPAN modules that use Data::Dumper June 30, 2007, 2:34 am
Javascript::SHA1 V 1.01 July 29, 2004, 7:19 am
Javascript::SHA1 V 1.03 August 12, 2007, 12:16 am
[ANN] Digest::SHA 5.28 (w/ shasum) November 18, 2004, 12:50 pm
Module Digest:SHA June 12, 2006, 8:00 am
LWP and Digest authentication February 8, 2007, 1:50 pm
ANNOUNCE: Digest::SHA 5.28 (w/ shasum) November 18, 2004, 7:42 pm
Difference in digest and md5_hex December 9, 2004, 5:32 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap