use IO::Socket::SSL::Utils; my $cert = PEM_file2cert('cert.pem'); # load certificate from file my $string = PEM_cert2string($cert); # convert certificate to PEM string CERT_free($cert); # free memory within OpenSSL my $key = KEY_create_rsa(2048); # create new 2048-bit RSA key PEM_string2file($key,"key.pem"); # and write it to file KEY_free($key); # free memory within OpenSSL
Creates an RSA key pair, bits defaults to 2048.
Creates an EC key, curve defaults to "prime256v1".
Extracts the information from the certificate into a hash and uses the given digest_algo (default: SHA-256) to determine digest of pubkey and cert. The resulting hash contains:
Creates a certificate based on the given hash. If the issuer is not specified the certificate will be self-signed. The following keys can be given:
If the CA option is given and true the defaults ``ca,sslca,emailca,objca'' are assumed, but can be overridden with explicit purpose. If the CA option is given and false the defaults ``server,client'' are assumed. If no CA option and no purpose is given it defaults to ``server,client''.
Purpose affects basicConstraints, keyUsage, extKeyUsage and netscapeCertType. The following purposes are defined (case is not important):
client server email objsign CA sslCA emailCA objCA emailProtection codeSigning timeStamping digitalSignature nonRepudiation keyEncipherment dataEncipherment keyAgreement keyCertSign cRLSign encipherOnly decipherOnly
Examples:
# root-CA for SSL certificates purpose => 'sslCA' # or CA => 1 # server certificate and CA (typically self-signed) purpose => 'sslCA,server' # client certificate purpose => 'client',