因此,几个星期以来,我一直在试图找出为什么我无法解密SOAP响应中的加密密钥元素。我采取了另一条路线,看看我是否可以用其他方法解密加密的密钥元素。在这种情况下,我使用openssl,我能够让它工作。
"C:\Program Files (x86)\GnuWin32\bin\openssl" enc -base64 -d -in encryptedKeyElement.txt > result.txt
"C:\Program Files (x86)\GnuWin32\bin\openssl" rsautl -decrypt -inkey myPrivateKey.pem -in encryptedKeyElement.txt -oaep -out decryptedkey.txt
使用解密的密钥,我可以解密肥皂体元素。
现在问题是这在.NET中不起作用了什么?
var encryptedKey = "AnQtlNmAapLaX862hobD/p/RaPStJ+ygqrJMN9LM6i1548auXJ5wk0SVeQTdiOVMe3wv9lhkXKAZD6u6rOUCa3es+xyHrdRBplg0mJBfkprz84AWcI36TsoOhmntLZF9Yr+ZMyYzOCfzK7T0b1rTYh2X2Wjbg8xu/KGuNic9HmF9l5fk4y2mQeM8C3ST+HACPDSrvhodAmucj9X0sWPA/v0Y116mevpWvUsekc6iMuAhfBfP2UaVO9HZofvk3WDP0LdBWOdOoifop5Sbz+QT3dt0u2u96Oi3wRLagXv56sHVvHsiNGuHyEhzRKF8rAhnjh4VQSruuDrM/PfaH4OgHg=="
var clientCert = new X509Certificate2(@"C:\eSar\certificates\xxxxxx.pfx", "xxxxx");
var rsa = (RSACryptoServiceProvider)clientCert.PrivateKey;
byte[] key = rsa.Decrypt(Convert.FromBase64String(encryptedKey), false);
我得到错误:
参数不正确。 {的 EDITED 即可。我输错了错误信息。遗憾]
堆栈跟踪
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.RSACryptoServiceProvider.DecryptKey(SafeKeyHandle pKeyContext, Byte[] pbEncryptedKey, Int32 cbEncryptedKey, Boolean fOAEP, ObjectHandleOnStack ohRetDecryptedKey)
at System.Security.Cryptography.RSACryptoServiceProvider.Decrypt(Byte[] rgb, Boolean fOAEP)
at Microsoft.Austria.WcfHelpers.SoapWithAttachments.SwaEncoder.ReadMessage(Stream stream, Int32 maxSizeOfHeaders, String contentType) in C:\Crap\Stuff\CARES\Microsoft.Austria.WcfHelpers.SoapWithAttachments\SwaEncoder.cs:line 503
at Microsoft.Austria.WcfHelpers.SoapWithAttachments.SwaEncoder.ReadMessage(Stream stream, Int32 maxSizeOfHeaders, String contentType) in C:\Crap\Stuff\CARES\Microsoft.Austria.WcfHelpers.SoapWithAttachments\SwaEncoder.cs:line 458
at Microsoft.Austria.WcfHelpers.SoapWithAttachments.SwaEncoder.ReadMessage(ArraySegment`1 buffer, BufferManager bufferManager, String contentType) in C:\Crap\Stuff\CARES\Microsoft.Austria.WcfHelpers.SoapWithAttachments\SwaEncoder.cs:line 126
at System.ServiceModel.Channels.HttpInput.DecodeBufferedMessage(ArraySegment`1 buffer, Stream inputStream)
at System.ServiceModel.Channels.HttpInput.ReadBufferedMessage(Stream inputStream)
at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(HttpRequestMessage httpRequestMessage, Exception& requestException)
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]: