当前位置: 首页>>代码示例>>C#>>正文


C# X509ContentType类代码示例

本文整理汇总了C#中X509ContentType的典型用法代码示例。如果您正苦于以下问题:C# X509ContentType类的具体用法?C# X509ContentType怎么用?C# X509ContentType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


X509ContentType类属于命名空间,在下文中一共展示了X509ContentType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Export

 public byte[] Export(X509ContentType contentType, string password)
 {
     // Export is for X509Certificate2Collections in their IStorePal guise,
     // if someone wanted to export whole stores they'd need to do
     // store.Certificates.Export(...), which would end up in the
     // CollectionBackedStoreProvider.
     Debug.Fail("Export was unexpected on a DirectoryBasedStore");
     throw new InvalidOperationException();
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:9,代码来源:DirectoryBasedStoreProvider.cs

示例2: Export

 public byte[] Export(X509ContentType contentType, string password)
 {
     switch (contentType)
     {
         case X509ContentType.Cert:
             return ExportX509Der();
         case X509ContentType.Pfx:
             return ExportPfx(password);
         default:
             throw new NotImplementedException();
     }
 }
开发者ID:rainersigwald,项目名称:corefx,代码行数:12,代码来源:CollectionBackedStoreProvider.cs

示例3: Export

 public byte[] Export(X509ContentType contentType, string password)
 {
     switch (contentType)
     {
         case X509ContentType.Cert:
             return ExportX509Der();
         case X509ContentType.Pfx:
             return ExportPfx(password);
         case X509ContentType.Pkcs7:
             return ExportPkcs7();
         case X509ContentType.SerializedCert:
         case X509ContentType.SerializedStore:
             throw new PlatformNotSupportedException(SR.Cryptography_Unix_X509_SerializedExport);
         default:
             throw new CryptographicException(SR.Cryptography_X509_InvalidContentType);
     }
 }
开发者ID:AndreGleichner,项目名称:corefx,代码行数:17,代码来源:ExportProvider.cs

示例4: Export

        public byte[] Export(X509ContentType contentType, string password)
        {
            switch (contentType)
            {
                case X509ContentType.Cert:
                    {
                        SafeCertContextHandle pCertContext = null;
                        if (!Interop.crypt32.CertEnumCertificatesInStore(_certStore, ref pCertContext))
                            return null;
                        try
                        {
                            unsafe
                            {
                                byte[] rawData = new byte[pCertContext.CertContext->cbCertEncoded];
                                Marshal.Copy((IntPtr)(pCertContext.CertContext->pbCertEncoded), rawData, 0, rawData.Length);
                                GC.KeepAlive(pCertContext);
                                return rawData;
                            }
                        }
                        finally
                        {
                            pCertContext.Dispose();
                        }
                    }

                case X509ContentType.SerializedCert:
                    {
                        SafeCertContextHandle pCertContext = null;
                        if (!Interop.crypt32.CertEnumCertificatesInStore(_certStore, ref pCertContext))
                            return null;

                        try
                        {
                            int cbEncoded = 0;
                            if (!Interop.crypt32.CertSerializeCertificateStoreElement(pCertContext, 0, null, ref cbEncoded))
                                throw Marshal.GetHRForLastWin32Error().ToCryptographicException();;

                            byte[] pbEncoded = new byte[cbEncoded];
                            if (!Interop.crypt32.CertSerializeCertificateStoreElement(pCertContext, 0, pbEncoded, ref cbEncoded))
                                throw Marshal.GetHRForLastWin32Error().ToCryptographicException();;

                            return pbEncoded;
                        }
                        finally
                        {
                            pCertContext.Dispose();
                        }
                    }

                case X509ContentType.Pkcs12:
                    {
                        unsafe
                        {
                            CRYPTOAPI_BLOB dataBlob = new CRYPTOAPI_BLOB(0, (byte*)null);

                            if (!Interop.crypt32.PFXExportCertStore(_certStore, ref dataBlob, password, PFXExportFlags.EXPORT_PRIVATE_KEYS | PFXExportFlags.REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY))
                                throw Marshal.GetHRForLastWin32Error().ToCryptographicException();;

                            byte[] pbEncoded = new byte[dataBlob.cbData];
                            fixed (byte* ppbEncoded = pbEncoded)
                            {
                                dataBlob.pbData = ppbEncoded;
                                if (!Interop.crypt32.PFXExportCertStore(_certStore, ref dataBlob, password, PFXExportFlags.EXPORT_PRIVATE_KEYS | PFXExportFlags.REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY))
                                    throw Marshal.GetHRForLastWin32Error().ToCryptographicException();;
                            }

                            return pbEncoded;
                        }
                    }

                case X509ContentType.SerializedStore:
                    return SaveToMemoryStore(CertStoreSaveAs.CERT_STORE_SAVE_AS_STORE);

                case X509ContentType.Pkcs7:
                    return SaveToMemoryStore(CertStoreSaveAs.CERT_STORE_SAVE_AS_PKCS7);

                default:
                    throw new CryptographicException(SR.Cryptography_X509_InvalidContentType);
            }
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:80,代码来源:StorePal.Export.cs

示例5: Export

 [System.Security.SecuritySafeCritical]  // auto-generated
 public virtual byte[] Export(X509ContentType contentType, SecureString password) {
     return ExportHelper(contentType, password);
 }
开发者ID:REALTOBIZ,项目名称:mono,代码行数:4,代码来源:x509certificate.cs

示例6: TestBlobContentType

 public static void TestBlobContentType(byte[] blob, X509ContentType contentType)
 {
     X509ContentType blobType = X509Certificate2.GetCertContentType(blob);
     Assert.Equal(contentType, blobType);
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:5,代码来源:ContentTypeTests.cs

示例7: Export

        public byte[] Export(X509ContentType contentType, string password) {
#if !FEATURE_CORESYSTEM
            //
            // We need to Assert all StorePermission flags since this is a memory store and we want 
            // semi-trusted code to be able to export certificates to a memory store.
            //

            StorePermission sp = new StorePermission(StorePermissionFlags.AllFlags);
            sp.Assert();
#endif

            Cryptography.SafeCertStoreHandle safeCertStoreHandle = X509Utils.ExportToMemoryStore(this);

            byte[] result = ExportCertificatesToBlob(safeCertStoreHandle, contentType, password);
            safeCertStoreHandle.Dispose();
            return result;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:17,代码来源:x509certificate2collection.cs

示例8: Export

        public virtual byte[] Export(X509ContentType contentType, string password)
        {
            if (!(contentType == X509ContentType.Cert || contentType == X509ContentType.SerializedCert || contentType == X509ContentType.Pkcs12))
                throw new CryptographicException(SR.Cryptography_X509_InvalidContentType);

            if (Pal == null)
                throw new CryptographicException(ErrorCode.E_POINTER);  // Not the greatest error, but needed for backward compat.

            using (IStorePal storePal = StorePal.FromCertificate(Pal))
            {
                return storePal.Export(contentType, password);
            }
        }
开发者ID:nbilling,项目名称:corefx,代码行数:13,代码来源:X509Certificate.cs

示例9: Export

 public byte[] Export(X509ContentType contentType, String password)
 {
     using (IStorePal storePal = StorePal.LinkFromCertificateCollection(this))
     {
         return storePal.Export(contentType, password);
     }
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:7,代码来源:X509Certificate2Collection.cs

示例10: Export

 public virtual byte[] Export(X509ContentType contentType);
开发者ID:ajit2936,项目名称:corefx-progress,代码行数:1,代码来源:System.Security.Cryptography.X509Certificates.cs

示例11: Export

		internal byte[] Export (X509ContentType contentType, byte[] password)
		{
			try {
				X509Helper.ThrowIfContextInvalid (impl);
				return impl.Export (contentType, password);
			} finally {
				// protect password
				if (password != null)
					Array.Clear (password, 0, password.Length);
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:11,代码来源:X509Certificate20.cs

示例12: Export

		public override byte[] Export (X509ContentType contentType, string password)
		{
			ThrowIfContextInvalid ();

			switch (contentType) {
			case X509ContentType.Cert:
				return GetRawCertData ();
			case X509ContentType.Pfx: // this includes Pkcs12
				return ExportPkcs12 (password);
			case X509ContentType.SerializedCert:
				// TODO
				throw new NotSupportedException ();
			default:
				string msg = Locale.GetText ("This certificate format '{0}' cannot be exported.", contentType);
				throw new CryptographicException (msg);
			}
		}
开发者ID:BrzVlad,项目名称:mono,代码行数:17,代码来源:X509CertificateImplBtls.cs

示例13: PosTest

    public bool PosTest(int id, string msg, X509ContentType x509ConType, TestDelegate d)
    {
        bool            retVal = true;
        X509Certificate cer;
        byte[]          bytes;

        TestLibrary.TestFramework.BeginScenario("PosTest"+id+": " + msg + " = " + x509ConType);

        try
        {
            cer   = new X509Certificate(c_CERTFILE);

            bytes = d(cer, x509ConType);

            if (null == bytes)
            {
                TestLibrary.TestFramework.LogError("000", "Export return null!");
                TestLibrary.TestFramework.LogInformation("");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("001", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation("");
            retVal = false;
        }

        return retVal;
    }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:30,代码来源:X509CertificateExports.cs

示例14: Export

		public static byte[] Export (X509CertificateImpl impl, X509ContentType contentType, byte[] password)
		{
			ThrowIfContextInvalid (impl);
			return impl.Export (contentType, password);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:5,代码来源:X509Helper.cs

示例15: NegTest

    public bool NegTest(int id, string msg, X509ContentType x509ConType, TestDelegate d)
    {
        bool            retVal = true;
        X509Certificate cer;
        byte[]          bytes;

        TestLibrary.TestFramework.BeginScenario("NegTest"+id+": "+msg+" = " + x509ConType);

        try
        {
            cer = new X509Certificate(c_CERTFILE);

            bytes = d(cer, x509ConType);

            TestLibrary.TestFramework.LogError("002", "Exception should have been thrown.");
            TestLibrary.TestFramework.LogInformation("");
            retVal = false;
        }
        catch (CryptographicException e)
        {
            // expected
            // ensure that the message does NOT contain "Unknown error"
            if (e.Message.ToLower().Contains("unknown error"))
            {
                TestLibrary.TestFramework.LogError("003", "Unexpected exception message (should not be unkown): " + e);
                TestLibrary.TestFramework.LogInformation("");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation("");
            retVal = false;
        }

        return retVal;
    }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:38,代码来源:X509CertificateExports.cs


注:本文中的X509ContentType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。