Ejemplo n.º 1
0
        /// <summary>GetX509FromPemFilePath</summary>
        /// <param name="pemFilePath">string</param>
        /// <param name="label">RFC7468Label</param>
        /// <returns>X509Certificate2</returns>
        public static X509Certificate2 GetX509FromPemFilePath(string pemFilePath, RFC7468Label label)
        {
            string pemString = File.ReadAllText(pemFilePath);

            return(new X509Certificate2(
                       PrivacyEnhancedMail.GetBytesFromPemString(
                           pemString, PrivacyEnhancedMail.EnumToString(label))));
        }
Ejemplo n.º 2
0
        /// <summary>GetBase64StringFromPemFilePath</summary>
        /// <param name="pemFilePath">string</param>
        /// <param name="label">RFC7468Label</param>
        /// <returns>Base64String</returns>
        public static string GetBase64StringFromPemFilePath(string pemFilePath, RFC7468Label label)
        {
            string pemString = File.ReadAllText(pemFilePath);

            return(CustomEncode.ToBase64String(
                       PrivacyEnhancedMail.GetBytesFromPemString(
                           pemString, PrivacyEnhancedMail.EnumToString(label))));
        }
Ejemplo n.º 3
0
        /// <summary>EnumToString</summary>
        public static string EnumToString(RFC7468Label label)
        {
            string _label = "";

            switch (label)
            {
            // Certificate
            case RFC7468Label.Certificate:
                _label = PrivacyEnhancedMail.CERTIFICATE;
                break;

            case RFC7468Label.X509Certificate:
                _label = PrivacyEnhancedMail.X509_CERTIFICATE;
                break;

            case RFC7468Label.X509Certificate2:
                _label = PrivacyEnhancedMail.X509_CERTIFICATE2;
                break;

            case RFC7468Label.TrustedCertificate:
                _label = PrivacyEnhancedMail.TRUSTED_CERTIFICATE;
                break;

            case RFC7468Label.NetscapeCertificateSequence:
                _label = PrivacyEnhancedMail.NETSCAPE_CERTIFICATE_SEQUENCE;
                break;

            case RFC7468Label.AttributeCertificate:
                _label = PrivacyEnhancedMail.ATTRIBUTE_CERTIFICATE;
                break;

            // PKCS7
            case RFC7468Label.PKCS7:
                _label = PrivacyEnhancedMail.PKCS7;
                break;

            case RFC7468Label.CertificateChain:
                _label = PrivacyEnhancedMail.CERTIFICATE_CHAIN;
                break;

            case RFC7468Label.PKCS7CertificateChain:
                _label = PrivacyEnhancedMail.PKCS7_CERTIFICATE_CHAIN;
                break;

            case RFC7468Label.CMS:
                _label = PrivacyEnhancedMail.CMS;
                break;

            // Key
            case RFC7468Label.PrivateKey:
                _label = PrivacyEnhancedMail.PRIVATE_KEY;
                break;

            case RFC7468Label.PublicKey:
                _label = PrivacyEnhancedMail.PUBLIC_KEY;
                break;

            case RFC7468Label.RsaPrivateKey:
                _label = PrivacyEnhancedMail.RSA_PRIVATE_KEY;
                break;

            case RFC7468Label.RsaPublicKey:
                _label = PrivacyEnhancedMail.RSA_PUBLIC_KEY;
                break;

            case RFC7468Label.DsaPrivateKey:
                _label = PrivacyEnhancedMail.DSA_PRIVATE_KEY;
                break;

            case RFC7468Label.DsaPublicKey:
                _label = PrivacyEnhancedMail.DSA_PUBLIC_KEY;
                break;

            case RFC7468Label.EncryptedPrivateKey:
                _label = PrivacyEnhancedMail.ENCRYPTED_PRIVATE_KEY;
                break;

            // CertificateRequest
            case RFC7468Label.CertificateRequest:
                _label = PrivacyEnhancedMail.CERTIFICATE_REQUEST;
                break;

            case RFC7468Label.NewCertificateRequest:
                _label = PrivacyEnhancedMail.NEW_CERTIFICATE_REQUEST;
                break;

            // CRL
            case RFC7468Label.CRL:
                _label = PrivacyEnhancedMail.CRL;
                break;

            case RFC7468Label.X509CRL:
                _label = PrivacyEnhancedMail.X509_CRL;
                break;

            // Parameters
            case RFC7468Label.EcParameters:
                _label = PrivacyEnhancedMail.EC_PARAMETERS;
                break;

            case RFC7468Label.DhParameters:
                _label = PrivacyEnhancedMail.DH_PARAMETERS;
                break;

            default:
                _label = "";
                break;
            }

            return(_label);
        }