我需要.pfx文件在IIS上的网站上安装https.
我有两个单独的文件:证书(.cer或pem)和私钥(.crt)但IIS只接受.pfx文件.
我显然安装了证书,它在证书管理器(mmc)中可用,但是当我选择证书导出向导时,我无法选择PFX格式(它是灰色的)
是否有任何工具可以做到这一点或C#以编程方式执行此操作的示例?
我已经看到了几个关于如何将PFX转换为证书文件的问题,但我需要采取另一种方式.
我有两个文件:
bob_cert.cert
bob_key.pem
我想将它们转换为单个.pfx文件.有没有这样做的工具?
我的应用程序将采用一组文件并对其进行签名.(我不是要尝试签署程序集.)有一个.p12文件,我从中获取私钥.
这是我试图使用的代码,但我得到了一个System.Security.Cryptography.CryptographicException "Invalid algorithm specified.".
X509Certificate pXCert = new X509Certificate2(@"keyStore.p12", "password");
RSACryptoServiceProvider csp = (RSACryptoServiceProvider)pXCert.PrivateKey;
string id = CryptoConfig.MapNameToOID("SHA256");
return csp.SignData(File.ReadAllBytes(filePath), id);
Run Code Online (Sandbox Code Playgroud)
根据这个答案,它无法完成(RSACryptoServiceProvider不支持SHA-256),但我希望可以使用不同的库,如Bouncy Castle.
我是新手,我发现Bouncy Castle非常混乱.我正在将一个Java应用程序移植到C#,我必须使用相同类型的加密来签名文件,所以我坚持使用RSA + SHA256.
我怎么能用Bouncy Castle,OpenSSL.NET,Security.Cryptography或其他我没有听说过的第三方库来做到这一点?我假设,如果它可以在Java中完成,那么它可以在C#中完成.
更新:
这是我从poupou的anwser链接中得到的
X509Certificate2 cert = new X509Certificate2(KeyStoreFile, password");
RSACryptoServiceProvider rsacsp = (RSACryptoServiceProvider)cert.PrivateKey;
CspParameters cspParam = new CspParameters();
cspParam.KeyContainerName = rsacsp.CspKeyContainerInfo.KeyContainerName;
cspParam.KeyNumber = rsacsp.CspKeyContainerInfo.KeyNumber == KeyNumber.Exchange ? 1 : 2;
RSACryptoServiceProvider aescsp = new RSACryptoServiceProvider(cspParam);
aescsp.PersistKeyInCsp = false;
byte[] signed = aescsp.SignData(File.ReadAllBytes(file), "SHA256");
bool isValid …Run Code Online (Sandbox Code Playgroud) 我有一个.PEM文件,其中包含用于SSL数据传输的公钥和私钥,如下所示:
-----BEGIN RSA PRIVATE KEY-----
private key data
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
public key data
-----END CERTIFICATE-----
Run Code Online (Sandbox Code Playgroud)
当我想通过以下代码加载.PEM文件时:
X509Certificate2 xx = new X509Certificate2("c:\\myKey.pem");
Run Code Online (Sandbox Code Playgroud)
我得到一个例外,说:"找不到请求的对象." ,满堆栈:
System.Security.Cryptography.CryptographicException was unhandled
Message=Cannot find the requested object.
Source=mscorlib
StackTrace:
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.X509Certificates.X509Utils._QueryCertFileType(String fileName)
at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName)
at DLLTest.SSL_Test.test() in E:\Projects\DLLTest\DLLTest\SSL_Test.cs:line 165
at DLLTest.SSL_Test.Run() in E:\Projects\DLLTest\DLLTest\SSL_Test.cs:line 21
at DLLTest.Program.Main(String[] args) in E:\Projects\DLLTest\DLLTest\Program.cs:line 21
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, …Run Code Online (Sandbox Code Playgroud) 这是我的代码.
X509Certificate pXCert = new X509Certificate2(@"keyStore.p12", "password");
RSACryptoServiceProvider csp = (RSACryptoServiceProvider)pXCert.PrivateKey;
string id = CryptoConfig.MapNameToOID("SHA256");
return csp.SignData(File.ReadAllBytes(filePath), id);
Run Code Online (Sandbox Code Playgroud)
在最后一行,我得到了例外:
System.Security.Cryptography.CryptographicException"指定的算法无效."
我究竟做错了什么?
更新:
id = 2.16.840.1.101.3.4.2.1
我有.crt和.pem文件
-----BEGIN CERTIFICATE-----
MIIFSDCCBDCg........................................
-----END CERTIFICATE-----
Run Code Online (Sandbox Code Playgroud)
我想要此文件中的RSA密钥。
任何人都不知道我们如何做到这一点。
我已经在命令下面一一使用了
openssl rsa -in XXX.crt -out input1.der -outform DER
openssl rsa -in input1.der -inform DER -out key.pem -outform PEM
Run Code Online (Sandbox Code Playgroud)
但是,它给出了错误:
无法加载私钥140331982231200:错误:0906D06C:PEM
例程:PEM_read_bio:无起始行:pem_lib.c:703:正在期待:任何私钥
而且我也使用了不同的命令,但它给出了以上错误。
cryptography ×3
.net ×2
c# ×2
certificate ×2
pem ×2
ssl ×2
bouncycastle ×1
crt ×1
iis ×1
key ×1
openssl ×1
private-key ×1
security ×1
windows ×1