HighInBC

Encrypted bitcoin paper wallet maker

Aug 31st, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.76 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # EXAMPLE IMAGE: http://images.highinbc.com/example_encrypted_paper_wallet.png
  3. # Needs a functioning copy of vanitygen in the same folder. Designed for linux, easily ported
  4. #  VERIFY any wallet before sending money to it, it is possible that text or QR code might get clipped so make sure
  5.  
  6. use strict;
  7. use Term::ReadKey;
  8. use GnuPG::Interface;
  9. use Image::Magick;
  10. use Data::Dumper;
  11.  
  12. print "Type your passphrase: ";
  13. ReadMode('noecho'); chomp(my $passphrase = <STDIN>); ReadMode(0);
  14. print "\nRepeat:             : ";
  15. ReadMode('noecho'); chomp(my $passphrase2 = <STDIN>); ReadMode(0);
  16. die "Passphrase mismatch\n" unless ( $passphrase eq $passphrase2 );
  17. print "\n\n";
  18.  
  19. my $gnupg = GnuPG::Interface->new();
  20. $gnupg->options->hash_init( armor => 1 );
  21.  
  22. my $g_in  = IO::Handle->new();
  23. my $g_out = IO::Handle->new();
  24. my $handles = GnuPG::Handles->new( stdin => $g_in, stdout => $g_out );
  25.  
  26. my $prefix = $ARGV[0];
  27. $prefix = '1'.$prefix unless( $prefix =~ m|^1| );
  28.  
  29. exit if ( $prefix =~ m/0/ );
  30.  
  31. # 1: Create keypair
  32. START:
  33. my $data    = `./vanitygen $prefix`;
  34. my $address = $1 if ( $data =~ m|Address: (.*)$|m );
  35. my $pk      = $1 if ( $data =~ m|Privkey: (.*)$|m );
  36.  
  37. print "Creating card with data:\n $data\n\n";
  38.  
  39. # 2: Create encrypted version
  40.  
  41. $gnupg->passphrase( $passphrase );
  42. my $pid = $gnupg->encrypt_symmetrically( handles => $handles );
  43. print $g_in ( "$pk\n\n" );
  44. close( $g_in );
  45. my $cipher = join( '', <$g_out> );
  46. waitpid $pid, 0;
  47. my $qr_cipher = $cipher;
  48. $qr_cipher =~ s/\n/./g;
  49.  
  50. # 2: Create template image
  51.  
  52. my $template = new Image::Magick;
  53. $template->Read( 'bitcoin_plain.png' ); # This can be blank or it could be a template of your own creation, dynamic data will be overlayed on top
  54.  
  55. # 4: Create image magick objects for qr codes
  56.  
  57. my $qr_public = new Image::Magick;
  58. $qr_public->Read( blob => `qrencode -o - -s 14 -lH -- $address`.'' );
  59.  
  60. my $qr_private = New Image::Magick;
  61. $qr_private->Read( blob =>  `qrencode -o - -lH -s 10 -- "$qr_cipher"`.'' );
  62.  
  63. # 5: Place the qr codes in the correct locations
  64.  
  65. $template->Composite( image => $qr_public,  compose => 'over', 'x' => 1300, 'y' =>  10 );
  66. $template->Composite( image => $qr_private, compose => 'over', 'x' =>   10, 'y' =>  10 );
  67.  
  68. # 6: Annotate the public key
  69.  
  70. $template->Annotate( text => $address,    font => 'fonts/amono.ttf',       pointsize => 42, fill => 'black', 'x' => 1940, 'y' =>   82, rotate => 90 );
  71. $template->Annotate( text => $cipher,     font => 'fonts/amono.ttf',       pointsize => 24, fill => 'black', 'x' =>   50, 'y' =>  850 );
  72.  
  73. # 7: Save the file
  74.  
  75. my $filename = "cards/card-encrypted-$address.png";
  76. $template->Write( $filename );
  77.  
  78. print "Verify PGP cipher:\n\n$cipher\n\n";
  79. <STDIN>;
  80. print "Verify image and QR codes:\n";
  81. system( '/usr/bin/eog', $filename );
Advertisement
Add Comment
Please, Sign In to add comment