Skip to content

Instantly share code, notes, and snippets.

@m-dango
Last active October 19, 2019 18:03
Show Gist options
  • Save m-dango/799b9fd3884430d76494dd40b3f04ea0 to your computer and use it in GitHub Desktop.
Save m-dango/799b9fd3884430d76494dd40b3f04ea0 to your computer and use it in GitHub Desktop.
#!/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