From: <272...@qq...> - 2019-12-01 03:21:13
|
I am used to generate keys with OpenSSL via shell, this way: ---------------------------------------------------------------------------- my $ssk="a29bRwoA73xZGeBc"; openssl req -new -newkey rsa:2048 -nodes -keyout "/etc/ssl/$ssk.key" -out "/etc/ssl/$ssk.csr" openssl x509 -req -days 365 -in "/etc/ssl/$ssk.csr" -signkey "/etc/ssl/$ssk.key" -out "/etc/ssl/$ssk.crt" ---------------------------------------------------------------------------- Now I need to perform this action via PERL, but I have no idea if the below code can at least implement the 1st line: ---------------------------------------------------------------------------- my $ssk="a29bRwoA73xZGeBc"; # I didn't use Crypt::OpenSSL::Random, as I didn't found where it comes to action use Crypt::OpenSSL::RSA; my $rsa=Crypt::OpenSSL::RSA->generate_key(2048); my $rsa_pub=Crypt::OpenSSL::RSA->new_public_key($rsa->get_public_key_x509_string()); my $rsa_prv=Crypt::OpenSSL::RSA->new_private_key($rsa->get_private_key_string()); my $cipher=$rsa->encrypt($rsa_pub); my $plain=$rsa->encrypt($cipher); my $sigt=$rsa_prv->sign($plain); # This seems to be part of the 2nd line in shell code, but maybe I am wrong. unless($rsa->verify($plain,$sigt)) { die "Failed to create keys"; } # Here is the issue: &SaveFile("/etc/ssl/$ssk.key",$plain,0400); # Is it correct? &SaveFile("/etc/ssl/$ssk.csr",$cipher,0400); # How about this? # How do I proceed to implement the 2nd line of the shell code? ---------------------------------------------------------------------------- Note that the part of Crypt::OpenSSL::Random and saving to key files is not docmented... Thanks a lot |