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.