Tag: x509certificate2

在x509certificate2中清空PrivateKey

我已使用私钥在本地计算机商店(win7)上安装了证书。 在c#代码中我这样做: X509Certificate2 cert = null; var store = new X509Store(storeName, storeLocation); store.Open(OpenFlags.ReadOnly); try { var result = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false); ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; cert = result.Count > 0 ? result[0] : null; } finally { store.Close(); } return cert; 在cert变量中,我有我的证书但是它有问题:HasPrivateKey是真的但是PrivateKey没有任何对象。 如果我使用我的Web应用程序的C#代码中的REST请求发送它我有错误: AcquireCredentialsHandle() failed with […]

如何使用System.Cryptography解密EncryptedAssertion

身份提供程序使用component pro的function加密Saml Assertion Dim encryptedSamlAssertion As New EncryptedAssertion(samlAssertion, encryptingCert, New System.Security.Cryptography.Xml.EncryptionMethod(SamlKeyAlgorithm.Aes256Cbc)) 在服务提供商处,我试图解密断言。 但我不能使用组件专业版。 我必须使用System.Security.Cryptography X509Certificate用于加密和解密 Aes256Cbc是加密算法 请帮助我提供一些有关如何使用X509Certificate和Aes256Cbc算法实现SamlAssertions解密的更多信息

我可以在ASP.NET中使用X509Certificate2而不使用证书存储吗?

我试图在Rackspace Cloud中的ASP.NET Web服务中使用X509Certificate。 我有一种感觉,云节点上的证书存储可能会导致问题。 我也有一个与此相关的问题,除了我在使用iPhone Apple推送通知提供程序(apns-sharp)C#时收到SslStream.AuthenticateAsClientexception 在apns-sharp项目中,我使用以下代码: certificate = new X509Certificate2(p12File) 但是我收到了一个exception并将代码更改为以下解决了X509Certificate2exception。 新代码如下: certificate = new X509Certificate2(p12File, String.Empty, X509KeyStorageFlags.MachineKeySet); 我想知道我是否可以在ASP.NET中使用X509Certificate2而不使用证书存储? 证书存储是否会导致Rackspace Cloud节点出现问题? 更新#1 Rackspace告诉我不允许访问本地机器证书商店。 有没有其他方法可以绕过使用证书存储区? 也许使用第三方图书馆?

如何使用存储在.NET Core 2中的Azure Key Vault中的PFX证书中的私钥?

我在C#中编写了一个ASP.NET Core 2.0网站并启用了Facebook身份validation,因此它需要HTTPS。 我正在使用原生的Kestrel Web服务器来托管该站点,并且有一个监听器设置为每个MS文档获取PFX证书。 从Key Key召回后,我似乎找不到让Kestrel识别私钥的方法。 我知道它存在,因为我写了两个调试语句,表明它实际存在。 这是我用来检索秘密的function,它正在工作。 public static async Task GetKeyVaultCert() { X509Certificate2 pfx; try { var kvClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetToken)); var secret = await kvClient .GetSecretAsync(“https://macscampvault.vault.azure.net/secrets/letsencrypt”).ConfigureAwait(false); byte[] bytes; if(secret.ContentType == “application/x-pkcs12”) bytes = Convert.FromBase64String(secret.Value); else { bytes = new byte[0]; Console.WriteLine(“secret is not PFX!!”); throw new ArgumentException(“This is not a […]

在Mono上使用X509Certificate2 – 使用公钥和私钥加载?

现在,我尝试像这样实例化X509Certificate2: cert = new X509Certificate2(Resources.cred); 其中Resources.cred是表示.pfx文件的byte[] 。 这在Windows / .NET上完全正常。 但是,在Mono JIT编译器版本3.2.8(Debian 3.2.8 + dfsg-4ubuntu1) (Ubuntu Server 14.04 LTS上的Mono )下运行相同的代码,我得到以下exception: System.TypeInitializationException: An exception was thrown by the type initializer for —> System.Security.Cryptography.CryptographicException: Unable to decode certificate. —> System.Security.Cryptography.CryptographicException: Input data cannot be coded as a valid certificate. —> System.Security.Cryptography.CryptographicException: Input data cannot be coded as […]

使用自签名证书

我有这个代码: X509Chain x509Chain = new X509Chain(); x509Chain.ChainPolicy.ExtraStore.Add(certificate1); x509Chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck; x509Chain.ChainPolicy.RevocationFlag = X509RevocationFlag.ExcludeRoot; x509Chain.Build(certificate2); foreach (X509ChainElement x509ChainElement in x509Chain.ChainElements) { Log(“Name: ” + x509ChainElement.Certificate.GetNameInfo(X509NameType.SimpleName, false)); foreach (X509ChainStatus x509ChainStatus in x509ChainElement.ChainElementStatus) Log(“status: ” + x509ChainStatus.StatusInformation); if (x509ChainElement.ChainElementStatus.Length != 0 && (x509ChainElement.Certificate.Thumbprint != certificate1.Thumbprint))// || x509ChainElement.ChainElementStatus[0].Status != X509ChainStatusFlags.UntrustedRoot)) return false; } 如果证书是自签名的(或者至少我认为它没有安装),我无法设法安装证书。 在状态日志消息我得到这个: 已处理证书链,但在信任提供程序不信任的根证书中终止 我怎么能忽略那张支票呢?

使用RSA AES提供程序生成自签名1024位X509Certificate2时出现问题

我正在尝试使用Microsoft AES加密提供程序生成X509Certificate2对象: CALG_AES_256(0x00006610)256位AES。 Microsoft AES加密提供程序支持此算法。 我的问题是我对CryptGenKey(providerContext, 0x6610, 0x4000001, out cryptKey)失败,出现以下错误: mscorlib.dll中发生未处理的“System.Runtime.InteropServices.COMException”类型exception 附加信息:指定了无效标志。 (HRESULTexception:0x80090009) 我正在使用的标志是(1024 << 16) | 1) (1024 << 16) | 1) 。 除非我弄错了, 根据MSDN上的文档 ,这不应该产生1024位可导出密钥吗? 我的方法有什么问题? 我的代码如下: using System; using System.Security; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Security.Cryptography.X509Certificates; namespace WebSockets { public struct SystemTime { public short Year; public short Month; public short DayOfWeek; […]

从远程主机自动下载X509证书链

我正在构建一些.net代码,它将在我们的一台服务器上按计划无人值守运行。 其执行的一部分要求它执行Java可执行文件,该可执行文件通过SSL与某些Web资源和服务进行通信。 如果它通过SSL做某事并且它没有远程证书链中的每一个证书,那么Java绝对会适合。 所以在.net中,我需要能够具体的https:// [无论] .com资源,并需要它在本地下载整个远程链。 为什么我要自动执行此操作? 因为我希望简化部署并且不必执行此操作4次,然后每次Oracle证书之一到期时再次执行此操作。 我这样做: X509Certificate2 lowestCert = SecurityHelper.DownloadSslCertificate(keyDownloadLocation); X509Chain chain = new X509Chain(); chain.Build(lowestCert); int counter = 0; foreach (X509ChainElement el in chain.ChainElements) { //Extract certificate X509Certificate2 chainCert = el.Certificate; //Come up with an alias and save location string alias = certBaseName + counter; string localLocation = Path.GetDirectoryName( System.Reflection.Assembly.GetEntryAssembly().Location ) […]

C#和dotnet 4.7.1没有为TLS 1.2调用添加自定义证书

我有以下C#代码,使用自定义证书构建https调用。 使用Tls 1.1时,通话正常。 使用Tls 1.2时,呼叫会中断。 我使用curl,使用tls 1.2工作正常。 C#代码: X509Certificate2Collection collection = new X509Certificate2Collection(); collection.Import(“C:\\SomePath\\MyCertificate.pfx”, “MyPassword”, X509KeyStorageFlags.PersistKeySet); var cert = collection[0]; ServicePointManager.SecurityProtocol = …; ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true; HttpClientHandler handler = new HttpClientHandler(); handler.ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true; handler.ClientCertificates.Add(cert); var content = new ByteArrayContent(Encoding.GetEncoding(“latin1”).GetBytes(“Hello world”)); HttpClient client = new […]

从RSACryptoServiceProvider创建X509Certificate2失败,无法找到请求的对象

示例代码: CspParameters cspParameters = new CspParameters(); cspParameters.ProviderType = 1; // PROV_RSA_FULL // Create the crypto service provider, generating a new // key. mRsaCSP = new RSACryptoServiceProvider(mDefaultKeyLength, cspParameters); mRsaCSP.PersistKeyInCsp = true; RSAParameters privateKey = mRsaCSP.ExportParameters(true); byte[] rsaBytes = mRsaCSP.ExportCspBlob(true); try { X509Certificate2 cert = new X509Certificate2(rsaBytes); mKeyDataPfx = Convert.ToBase64String(cert.Export(X509ContentType.Pkcs12, password)); } catch (Exception ce) { string […]