Skip to content

Instantly share code, notes, and snippets.

@h0tw1r3
Last active October 16, 2025 13:32
Show Gist options
  • Select an option

  • Save h0tw1r3/124e5d152a0af25f58721b0e0e0d4579 to your computer and use it in GitHub Desktop.

Select an option

Save h0tw1r3/124e5d152a0af25f58721b0e0e0d4579 to your computer and use it in GitHub Desktop.
decrypt rsa private key with just perl
#!/usr/bin/env perl
use strict;
use warnings;
use Net::SSLeay;
# Check for the correct number of command-line arguments
unless (@ARGV == 3) {
die "Usage: perl $0 <encrypted_key_file> <passphrase_file> <decrypted_key_file>\n";
}
# Assign command-line arguments to variables
my ($encrypted_key_file, $passphrase_file, $decrypted_key_file) = @ARGV;
# Read passphrase from file
open my $pass_fh, '<', $passphrase_file or die "Cannot open passphrase file '$passphrase_file': $!";
chomp(my $passphrase = <$pass_fh>);
close $pass_fh;
my $ctx = Net::SSLeay::CTX_new() or die "Failed to create SSL context: $!";
# Create a BIO object for the input file
my $bio = Net::SSLeay::BIO_new_file($encrypted_key_file, 'r');
unless ($bio) {
die "Failed to create BIO for '$encrypted_key_file': $!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment