我在这个问题上已经被困了将近两天了,我似乎找不到任何解决办法。我在我的机器上承载了一个WCF服务,它包含一个接受两个字符串参数的方法SendCredentials。
现在,我应该向我的服务发送一个公钥,它将通过它进行加密(异步加密),并将一些信息发送回客户端。
我无法将该公钥从客户端传递到服务方法,因为在XML中,format.Here是我的客户端代码:
$(document).ready(function () {
$("#btnSend").click(function () {
debugger;
jQuery.support.cors = true;
var doOaepPadding = true;
var rsa = new System.Security.Cryptography.RSACryptoServiceProvider();
_privateKey = rsa.ToXmlString(true);
_publicKey = rsa.ToXmlString(false);
var data = $("#txtName").val();
var name = "testvalue";
var _privateKey = rsa.ToXmlString(true);
**var _publicKey = rsa.ToXmlString(false);**
//<![CDATA[ and ]]>;
$.ajax({
type: "POST",
url: 'http://localhost:51348/TestService.svc/SendCredentials',
crossDomain: true,
data:JSON.stringify({ mac: "bac", pubKey: _publicKey }),
contentType: "application/json",
dataType: "json",
success: function (result) {
var ans = JSON.stringify(result);
alert(ans);
// result = new XMLSerializer().serializeToString(result.documentElement);
},
error: function (xhr, err) {
alert("readyState: " + xhr.readyState + "\nstatus: " + xhr.status);
alert("responseText: " + xhr.responseText);
}
});
return false;
});
});
</script>_publicKey是我想传递的变量,但抛出了上述错误。对于我如何传递这个XML变量的任何建议,我们都会非常感激。
发布于 2015-07-06 10:24:13
我建议您将_publicKey转换为base64字符串。
将_publicKey转换为字符串,然后使用字节数组
Convert.ToBase64String(byte[] inArray)在服务端做相反的事情
System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(endodedString), true));https://stackoverflow.com/questions/31243094
复制相似问题