I'm trying to understand more about X.509 Digital Certificates. There seems to be lots of contradiction around. I am using Bouncy Castle
to generate a key pair, using
public static void SaveToFile(X509Certificate newCert, AsymmetricCipherKeyPair kp, string filePath, string certAlias, string password)
{
var newStore = new Pkcs12Store();
var certEntry = new X509CertificateEntry(newCert);
newStore.SetCertificateEntry(certAlias, certEntry);
newStore.SetKeyEntry(certAlias,
new AsymmetricKeyEntry(kp.Private), new[] { certEntry });
using (var certFile = File.Create(filePath))
newStore.Save(certFile, password.ToCharArray(), new SecureRandom(new CryptoApiRandomGenerator()));
}
This saves the generated certificate to disk. Some articles tell us there is no need to password protect the certificate as there is no PRIVATE KEY
stored in there. Then this article says the certificate does indeed contain the PRIVATE KEY
.
I guess I have two questions that will hopefully help me understand this:
- If I generate my keys in this way, should the password be the SAME as the passphrase for the
PRIVATE KEY
? - Do I distribute the X.509 certificate to prove the
PUBLIC KEY
is mine (being paired to my name in the certificate) or should the certificate be kept as safe and secret as thePRIVATE KEY
and what use is a self-signed certificate?