I have a task: generate private/public key pairs for banks.
User data like State, City, Company, Name, Email, and some other data should be included. How I can generate those keys with PHP or Shell?
UPDATE 1
I need a private key and cert for a Bank.
Private&public key pairs do not contain identifying information like name and address. Certificates do (and also certificate requests, since those are meant to be turned into certificates).
The
openssl
command can generate both key pairs and certificate requests, and it can sign certificate requests to produce certificates as well. First, figure out exactly which kinds of objects you need, whether you need to use a central CA to sign certificates, etc... Then you should be able to easily find information on what arguments you need to pass to generate each type of object.What type of private/public are you need? Someone who said you to do this must provide algorythm or type of keys. There is a huge variety of private/public key types, not only RSA.
Here are PHP codes to generate PRIVATE and PUBLIC KEYS:
===method A) ====
====method b) =======
include this [phpsec open-source library][1](with [examples][2]), and then execute:
PHP offers interface to OpenSSL functions. You need to generate a certificate (the keypair can't include user data), and this is a bit more complicated than generating a keypair. You can generate self-signed certificates (in such certificates Issuer and Subject fields are identical), which is probably what you need.
If you need a CA-signed certificate, than you need to generate a certificate signing request (CSR) and a private key, then send a CSR to the certificate authority that will sign it and send you back the certificate (remember that private key remains on your side, so you need to save it).
Also, google search revealed a good tutorial for you.
Here is a shell script that I use for generating certificates using openssl. This is just a test script I wrote, so you might want to set some additional security. Having passwords written somewhere is not a good idea. You might want to run it thoroughly in your test environment or tweak as you like.
Here is what it requires:
There is only 1 only requirement, the ca private key file should not be password protected. If it is, you can run:
Lets say I stored filename in CERT_FILE_NAME.
In the end you will get a folder with the name you provided (filename) containing: cert in pem format (filename.pem), cert in crt format (filename.crt), cert in der (binary format, (filename.der)), cert in password protected .p12 format (filename.p12), cert private key password protected (filename_Password.key) and cert private key non password protected. (filename_NoPassword.key)
Now the contents of the text files that we used (every item in newline):
cert.input:
pass.input:
caconfirm.input: