我对HttpWebRequest和配对密钥有疑问。
我需要使用两个密钥发送已签名的请求:public.cer和private.key。
我有要求:
POST /webservice/deposition/api/testDeposition HTTP/1.1
Host: bo-demo02.yamoney.ru:9094
Content-Type: application/pkcs7-mime
-----BEGIN PKCS7-----
MIICwwYJKoZIhvcNAQcCoIICtDCCArACAQExDzANBglghkgBZQMEAgEFADAUBgkq
hkiG9w0BBwGgBwQFMTIzNDUxggKCMIICfgIBATBaMEMxEjAQBgoJkiaJk/IsZAEZ
FgJydTEXMBUGCgmSJomT8ixkARkWB3lhbW9uZXkxFDASBgNVBAMTC05CQ08gWU0g
SW50AhMXAAAyWMctdSmMY7pIAAAAADJYMA0GCWCGSAFlAwQCAQUAoIH6MBgGCSqG
SIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcNAQkFMQ8XDTE4MDkxOTA0MDU1
MVowLwYJKoZIhvcNAQkEMSIEIFmURxq7AREq/MGBWfbMdLT1EbmYBtpZs8r1qcFz
ys/FMIGOBgkqhkiG9w0BCQ8xgYAwfjALBglghkgBZQMEASowCAYGKoUDAgIJMAgG
BiqFAwICFTALBglghkgBZQMEARYwCwYJYIZIAWUDBAECMAoGCCqGSIb3DQMHMA4G
CCqGSIb3DQMCAgIAgDANBggqhkiG9w0DAgIBQDAHBgUrDgMCBzANBggqhkiG9w0D
AgIBKDANBgkqhkiG9w0BAQEFAASCAQA3pfE/pzEnUoewSNfjVORE9Tg+c+fku+Kh
gvA7ZQM/BkHMZ6rQF22XPeaMhIm229UXqCVV2yKacBnPutLvKCS7B4d+HHK0UQX8
OhOUhACVYjSOj/lKg3TEZ/8MZN6z72BviLuleTdHHjue1InQzlv04huJP4chN4Lb
QWbxoxVi9B9jYRGjWNk8QfI7Yu3MIzOYjMeku0v0asEWw2LyOgI51xslvrAetOIr
tUc0DYOoxbHJNsgYncsZ/l+9S0P9qCLIEI3eY4mPlPFxaMvHRhvOPCBqwbuddGop
16EGXpt6ScofoQoyxi9MZu+VsuRePs5LhI5eim7G8FxxGoIvPazA
-----END PKCS7-----
我想使用两个键发送此请求。
我知道如何用curl做到这一点。
curl -v -H "Content-Type: application/pkcs7-mime" -k --cert public.cer --key private.key --pass MyPassKey POST "https://bo-demo02.yamoney.ru:9094/webservice/deposition/api/testDeposition" --data "MY_DATA_REQUEST"
但是还有一个问题,因为它是一行,并且上面的请求包含到新行的转换,所以将无法发送请求。
例如,在这里,我尝试使用cmd通过Process.Start()完成此操作。但是只剩下第一行。
curl -v -H "Content-Type: application/pkcs7-mime" -k --cert public.cer --key private.key --pass MyPassKey POST "https://bo-demo02.yamoney.ru:9094/webservice/deposition/api/testDeposition" --data "-----BEGIN PKCS7-----"
“ ----- BEGIN PKCS7 -----”,而不是整个请求。
然后,我尝试根据这些密钥创建pfx,并使用HttpWebRequest发送它们。
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = "application/pkcs7-mime";
httpWebRequest.Method = "POST";
httpWebRequest.ClientCertificates.Add(new X509Certificate2("./cert.pfx", "password"));
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write(data);
streamWriter.Flush();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
return result;
}
那也不起作用。
是否可以使用HttpWebRequest方法中的两个键对请求进行签名?
这样的示例:
httpWebRequest.SignCertificates(new PublicKey("path.cer"), new PrivateKey("path.key", "password"));