The hashed text from
crypt can be longer than 8 characters unless you are working with ancient implementation
#!/usr/bin/env perl
use strict;
use warnings;
# a non-random salt == 'salt'
#SHA256
print crypt("secret",'$5$salt');
print "\n";
#SHA512
print crypt("secret",'$66salt');
print "\n";
# Oops, security gone, that is not what I meant
# I meant this
print crypt("secret",'$6$salt');
You also have
Digest, which is core
#!/usr/bin/env perl
use strict;
use warnings;
use Digest;
my $algo = 'SHA-512';
sub hash {
my $string = shift;
my $salt;
# bless whoever wrote this
$salt .= join '',('.','/',(0..9),"a".."z","A".."Z")[rand 64] for (
+1..8);
my $hasher = Digest->new($algo);
$hasher->add($salt);
$hasher->add($string);
return $salt . $hasher->b64digest();
}
sub checkHash {
# First 8 characters are salt
my $hash = shift;
my $string = shift;
my $salt = substr($hash,0,8);
my $hasher = Digest->new($algo);
$hasher->add($salt);
$hasher->add($string);
return $hash eq $salt . $hasher->b64digest();
}
my $hash = hash('blahblah');
print "match" if checkHash($hash,'blahblah');
for encryption, you can xor, read more here
Encryption using perl core functions only.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.