This repository has been archived by the owner on Dec 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
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
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; |