Web Service with Https in C++ 非托管方式
2007-04-04 18:28
453 查看
自动生成的代码是不能直接使用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();
}
参考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();
}
相关文章推荐
- Debugging Maya Plugin(C++) with CodeBlocks in Linux
- SharePoint Add-in Model (App Model) 介绍 – 概念、托管方式、开发语言
- c++ 非托管程序调用c#托管程序l的实现操作方式
- Longest Substring Without Repeating Characters 7 lines with c++ in 12ms
- rectify propeties in c++ coding with opencv
- 《C++ Concurrency in Action》笔记15 a thread-safe queue with condition variable
- SPRING IN ACTION 第4版笔记-第十章Hitting the database with spring and jdbc-003-四种方式获取DataSource
- Programming with ADO in Visual C++
- Creating an AVI in memory with C++
- Regular Expressions in C++ with Boost.Regex(1)
- Polymorphism in Perl comparing with JAVA and C++
- Problem with ctor in C++
- Parsing C++ in Python with Clang
- Getting Started with C++ in Visual Studio
- C++ 通过代码托管的方式调用c#的httpAgilityPack库
- Ch3-4: solve Hanoi in C++ with recursion, and with stack explicitly
- Configuration to access by HTTPS with SSL in Apache HTTP
- [Tutorial] How to build a GUI in ROS with Qt / C++?
- From CString to char * in C++ with unicode setting
- How to get the password text in a text with password property from another process using C++ - 用C++如何从不同进程获取密码框文本