Web Service with Https in C++ 非托管方式

自动生成的代码是不能直接使用HTTPS

参考MSDN:SecureSOAP 示例
http://msdn2.microsoft.com/zh-cn/library/s2ya483s(VS.80).aspx

强烈建议不要将Web Service走SSL,太慢了~

owner deal with en/decryption

the following code extract from internet:

http://community.csdn.net/Expert/TopicView3.asp?id=4873326

未处理的“System.Security.Cryptography.CryptographicException”类型的异常出现在mscorlib.dll 中。
其他信息:不正确的长度。

加密代码:
private void button1_Click(object sender, System.EventArgs e)
{
string PublicKey="<RSAKeyValue><Modulus>5eELzKltl6pSPJ1JAjt093vYzBvoj/tOEkJInwAZJNnmGy5o1b24hK4+O6affZNfNWwMxO1NMlYzkXKfhwUImzs5AVuo0wkRERvUTgZiFxSNtqZ2Z6tbpvjg2iw7j++N7pBvkIDGE74npcVlNZi7SyXCe5ldKxgxWQxtMX+Eoek=</Modulus><Exponent>AQAB</Exponent><P>/ay65e9ZmlifpI4e7xtAfBQvHnk1H2jN7d7hQmeswxZGiRKwMMZxrMFNK+stuQrXgtmXZ7ULkmReBpFgQx6Ehw==</P><Q>5/x6O205dCYdko/sx1p7FNxUbwAIHWlhILQKIV9Rmj2dUnXzt5nO8scN5gM/azQyQSkQigthMLpgOUzAnQOyDw==</Q><DP>ti3Ig71jIj+nVuxiNuHha7qrJD1z8zy3N6+rIp+GKQzkVyi+tCiwFps0KuhZC91HbMeLvoT87IN8K0dYVJukHQ==</DP><DQ>g+5TOW6xiPuQP+S4HNu5ObDgF8xl0Qw4H5gkVrxVtSkrSlUoSJchWXKY1eGs9HPXzLTk4gz8tfCYfp3GwMT0Qw==</DQ><InverseQ>W+JEpf7UnWwSmLsie6i5xw+ZuWw3hvZ/LecLepyXBdLv/jW4a17omXgWK1UqkH5p8DwbXOudQpii1+7zXpBQuw==</InverseQ><D>cDgpY3K+blCWLsL1liJiWkJaNmHVaRxcI2u6Oex5WdUJkPFZ+iXQwuywsrwHlezwiIrDvQq/KbiNGg7js60QYpIzTZaUDJONBWlcVAjiMFaS0hP72s/1SdXWz5+J0Fqa/QkMxikrZCHJz1TGwtqioeRPGcr0KLItD+aWXJ4CFLU=</D></RSAKeyValue>";

FileStream fsFile = new FileStream("aa.txt",FileMode.Open);
StreamReader fsRead=new StreamReader(fsFile,System.Text.Encoding.GetEncoding("GB2312"),true);

FileStream fsFile1 = new FileStream("bb.txt",FileMode.Create);
StreamWriter fsWrite=new StreamWriter(fsFile1);

string sStr=fsRead.ReadLine();
while(sStr != null)
{
rsa.FromXmlString(PublicKey);
byte[] done1 = rsa.Encrypt(new UnicodeEncoding().GetBytes(sStr),false);
fsWrite.WriteLine(Convert.ToBase64String(done1));
sStr=fsRead.ReadLine();
}
fsRead.Close();
fsFile.Close();

fsWrite.Close();
fsFile.Close();
}


解密代码:
private void button2_Click(object sender, System.EventArgs e)
{
string PrivateKey="<RSAKeyValue><Modulus>5eELzKltl6pSPJ1JAjt093vYzBvoj/tOEkJInwAZJNnmGy5o1b24hK4+O6affZNfNWwMxO1NMlYzkXKfhwUImzs5AVuo0wkRERvUTgZiFxSNtqZ2Z6tbpvjg2iw7j++N7pBvkIDGE74npcVlNZi7SyXCe5ldKxgxWQxtMX+Eoek=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";

FileStream fsFile = new FileStream("bb.txt",FileMode.Open);
StreamReader fsRead=new StreamReader(fsFile,System.Text.Encoding.GetEncoding("GB2312"),true);

FileStream fsFile1 = new FileStream("cc.txt",FileMode.Create);
StreamWriter fsWrite=new StreamWriter(fsFile1);

string sStr=fsRead.ReadLine();
while(sStr != null)
{
rsa.FromXmlString(PrivateKey);
byte[] done1 = rsa.Decrypt(Convert.FromBase64String(sStr),false);
fsWrite.WriteLine((new UnicodeEncoding()).GetString(done1));
sStr=fsRead.ReadLine();
}
fsRead.Close();
fsFile.Close();

fsWrite.Close();
fsFile.Close();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值