Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
Add perl signing example
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed Nov 20, 2015
1 parent 3e3d6fa commit 49dfe7c
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions assets/signing/sign-message.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/perl
#
# Echoes the signed message and exits
# usage: ./sign-message.pl "test"
#
#########################################################
# WARNING WARNING WARNING #
#########################################################
# #
# This file is intended for demonstration purposes #
# only. #
# #
# It is the SOLE responsibility of YOU, the programmer #
# to prevent against unauthorized access to any signing #
# functions. #
# #
# Organizations that do not protect against un- #
# authorized signing will be black-listed to prevent #
# software piracy. #
# #
# -QZ Industries, LLC #
# #
#########################################################

# RSA Crypto libs provided by:
# Debian: libcrypt-openssl-rsa-perl
# RedHat: perl-Crypt-OpenSSL-RSA
use Crypt::OpenSSL::RSA;
use MIME::Base64 qw(encode_base64);

# Get first argument passed to script
my $request = $ARGV[0];

# Path to the private key
my $pem_file = "private-key.pem";

# Read private key
my $private_key = do {
local $/ = undef;
open my $fh, "<", $pem_file
or die "could not open $file: $!";
<$fh>;
};

# Load private key
my $rsa = Crypt::OpenSSL::RSA->new_private_key($private_key);

# Create signature
my $sig = encode_base64($rsa->sign($request));

print $sig;

0 comments on commit 49dfe7c

Please sign in to comment.