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

Re: crypto with core modules only

by trippledubs (Deacon)
on Aug 28, 2018 at 18:32 UTC ( [id://1221277]=note: print w/replies, xml ) Need Help??


in reply to crypto with core modules only

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-19 06:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found