コード例 #1
0
        internal static X509Certificate2 GetCertificateFromPEMstring(string publicCert, string privateKey)
        {
            var certBuffer = GetBytesFromPEM(publicCert, PemStringType.Certificate);
            var keyBuffer  = GetBytesFromPEM(privateKey, PemStringType.RsaPrivateKey);

            var certificate = new X509Certificate2(certBuffer);

            var prov = CertificateCrypto.DecodeRsaPrivateKey(keyBuffer);

            certificate.PrivateKey = prov;

            return(certificate);
        }
コード例 #2
0
        internal static X509Certificate2 GetCertificateFromPEMstring(string publicCert, string privateKey, string password)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                password = "";
            }
            var certBuffer = GetBytesFromPEM(publicCert, PemStringType.Certificate);
            var keyBuffer  = GetBytesFromPEM(privateKey, PemStringType.RsaPrivateKey);

            var certificate = new X509Certificate2(certBuffer, password, X509KeyStorageFlags.MachineKeySet);

            var prov = CertificateCrypto.DecodeRsaPrivateKey(keyBuffer);

            certificate.PrivateKey = prov;

            return(certificate);
        }