#!/usr/bin/perl -w # ssh://git.mdcc.cx/git/ad1810-stuff.git git/ad1810-stuff/scripts # june 2025 # based upon # https://github.com/dehydrated-io/dehydrated/wiki/Import-from-official-letsencrypt-client # Depends: libcrypt-openssl-rsa-perl, libfile-slurper-perl # Import account key # # If for any reason you want to import your existing account key from the # official letsencrypt client place this perl script next to private_key.json # (should be in a subdirectory under # /etc/letsencrypt/accounts/acme-v01.api.letsencrypt.org/directory) and run it. # It should return your private key in PEM format, which you can pipe directly # into private_key.pem. use strict; use Crypt::OpenSSL::RSA; use Crypt::OpenSSL::Bignum; use JSON; use File::Slurper 'read_text'; use MIME::Base64; my $json_file = "private_key.json"; my $json_content = read_text($json_file); $json_content =~ tr/-/+/; $json_content =~ tr/_/\//; my $json = decode_json($json_content); my $n = Crypt::OpenSSL::Bignum->new_from_bin(decode_base64($json->{n})); my $e = Crypt::OpenSSL::Bignum->new_from_bin(decode_base64($json->{e})); my $d = Crypt::OpenSSL::Bignum->new_from_bin(decode_base64($json->{d})); my $p = Crypt::OpenSSL::Bignum->new_from_bin(decode_base64($json->{p})); my $q = Crypt::OpenSSL::Bignum->new_from_bin(decode_base64($json->{q})); my $rsa = Crypt::OpenSSL::RSA->new_key_from_parameters($n, $e, $d, $p, $q); print($rsa->get_private_key_string());