public static AsymmetricAlgorithm LoadPrivateKey(string privateKeyPem) { var keyType = DetectKeyType(privateKeyPem); var privateKeyBytes = PemDecoder.DecodeSection(privateKeyPem, keyType); var privateKey = GetPrivateKey(keyType, new ReadOnlyMemory <byte>(privateKeyBytes)); return(privateKey); }
/// <summary> /// https://8gwifi.org/PemParserFunctions.jsp /// </summary> /// <param name="pemCertificate">A pem string type CERTIFICATE with, without private key</param> /// <param name="password"></param> /// <returns></returns> public X509Certificate2 PemImportCertificate(string pemCertificate, string password = null) { var certBytes = PemDecoder.DecodeSection(pemCertificate, PemTypes.CERTIFICATE); if (string.IsNullOrEmpty(password)) { var certificate = new X509Certificate2(certBytes); return(certificate); } else { var certificate = new X509Certificate2(certBytes, password); return(certificate); } }