Skip to content

Instantly share code, notes, and snippets.

@beezly
Created July 16, 2012 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beezly/3121789 to your computer and use it in GitHub Desktop.
Save beezly/3121789 to your computer and use it in GitHub Desktop.
SHA512 crypt function
use String::Random qw(random_regex);
sub encrypt {
my $password = shift;
my $salt = random_regex('[0-9A-Za-z./]{16}');
return crypt($password,'$6$'.$salt);
}
@beezly
Copy link
Author

beezly commented Jul 16, 2012

Perl SHA-512 encrypt function which uses the native libc SHA-512 implementation. Definitely works on Solaris 10 and Linux with glibc > 2.7.

@beezly
Copy link
Author

beezly commented Jul 16, 2012

If you want a cross platform implementation that doesn't depend on the libc crypt, it's probably worth looking at this: http://stackoverflow.com/questions/11017330/creating-glibc-2-7-style-sha-512-crypt-hashes-in-perl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment