예제 #1
0
        /// <summary>
        /// Creates a new certificate and saves it as X.509 cert file and a PFX file
        /// </summary>
        private static void Create()
        {
            // Create a self-signed cert
            byte[] pfxBytes = CertUtil.CreateSelfSignedCert(
                new X500DistinguishedName("CN=Windows Azure Tools"),
                keyAlias,
                DateTime.Now,
                expirationDate,
                password);

            // Write the cert into the .pfx file
            File.WriteAllBytes(pfxFileName, pfxBytes);

            // Export as x.509 cert (without the public key)
            byte[] cerBytes = new X509Certificate2(pfxBytes, password).Export(X509ContentType.Cert);

            // Write into the .cer file
            File.WriteAllBytes(certFileName, cerBytes);
        }