Last active
October 19, 2019 18:03
-
-
Save m-dango/799b9fd3884430d76494dd40b3f04ea0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use feature qw(say); | |
use if $^O eq 'MSWin32', 'Win32::API'; | |
use if $^O eq 'linux', 'Linux::Perl::getrandom'; | |
my $bytes = int( $ARGV[0] // 8 ); | |
my $buffer = "\0" x $bytes; | |
if ( $^O eq 'MSWin32' ) { | |
my $function = Win32::API::More->new( qw{ bcrypt BCryptGenRandom PPNN N } ); | |
$function->Call( 0, $buffer, $bytes, 2 ); | |
} | |
elsif ( $^O eq 'linux' ) { | |
Linux::Perl::getrandom->getrandom( buffer => \$buffer ); | |
} | |
say unpack( 'H*', $buffer ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment