Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # EXAMPLE IMAGE: http://images.highinbc.com/example_encrypted_paper_wallet.png
- # Needs a functioning copy of vanitygen in the same folder. Designed for linux, easily ported
- # VERIFY any wallet before sending money to it, it is possible that text or QR code might get clipped so make sure
- use strict;
- use Term::ReadKey;
- use GnuPG::Interface;
- use Image::Magick;
- use Data::Dumper;
- print "Type your passphrase: ";
- ReadMode('noecho'); chomp(my $passphrase = <STDIN>); ReadMode(0);
- print "\nRepeat: : ";
- ReadMode('noecho'); chomp(my $passphrase2 = <STDIN>); ReadMode(0);
- die "Passphrase mismatch\n" unless ( $passphrase eq $passphrase2 );
- print "\n\n";
- my $gnupg = GnuPG::Interface->new();
- $gnupg->options->hash_init( armor => 1 );
- my $g_in = IO::Handle->new();
- my $g_out = IO::Handle->new();
- my $handles = GnuPG::Handles->new( stdin => $g_in, stdout => $g_out );
- my $prefix = $ARGV[0];
- $prefix = '1'.$prefix unless( $prefix =~ m|^1| );
- exit if ( $prefix =~ m/0/ );
- # 1: Create keypair
- START:
- my $data = `./vanitygen $prefix`;
- my $address = $1 if ( $data =~ m|Address: (.*)$|m );
- my $pk = $1 if ( $data =~ m|Privkey: (.*)$|m );
- print "Creating card with data:\n $data\n\n";
- # 2: Create encrypted version
- $gnupg->passphrase( $passphrase );
- my $pid = $gnupg->encrypt_symmetrically( handles => $handles );
- print $g_in ( "$pk\n\n" );
- close( $g_in );
- my $cipher = join( '', <$g_out> );
- waitpid $pid, 0;
- my $qr_cipher = $cipher;
- $qr_cipher =~ s/\n/./g;
- # 2: Create template image
- my $template = new Image::Magick;
- $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
- # 4: Create image magick objects for qr codes
- my $qr_public = new Image::Magick;
- $qr_public->Read( blob => `qrencode -o - -s 14 -lH -- $address`.'' );
- my $qr_private = New Image::Magick;
- $qr_private->Read( blob => `qrencode -o - -lH -s 10 -- "$qr_cipher"`.'' );
- # 5: Place the qr codes in the correct locations
- $template->Composite( image => $qr_public, compose => 'over', 'x' => 1300, 'y' => 10 );
- $template->Composite( image => $qr_private, compose => 'over', 'x' => 10, 'y' => 10 );
- # 6: Annotate the public key
- $template->Annotate( text => $address, font => 'fonts/amono.ttf', pointsize => 42, fill => 'black', 'x' => 1940, 'y' => 82, rotate => 90 );
- $template->Annotate( text => $cipher, font => 'fonts/amono.ttf', pointsize => 24, fill => 'black', 'x' => 50, 'y' => 850 );
- # 7: Save the file
- my $filename = "cards/card-encrypted-$address.png";
- $template->Write( $filename );
- print "Verify PGP cipher:\n\n$cipher\n\n";
- <STDIN>;
- print "Verify image and QR codes:\n";
- system( '/usr/bin/eog', $filename );
Advertisement
Add Comment
Please, Sign In to add comment