gpt4 book ai didi

c# - Phpseclib 在 session 中生成 RSA key (使用 C# 客户端)

转载 作者:太空宇宙 更新时间:2023-11-03 15:08:37 25 4
gpt4 key购买 nike

我想在 PHP 和 C# 之间进行 RSA 通信。我尝试使用 phpseclib但我有一些问题。

这是我在服务器上创建 key 的方式:

$rsa = new Crypt_RSA();
extract($rsa->createKey());
$_SESSION['RSAPubKey'] = $publickey;
$_SESSION['RSAPrivKey'] = $privatekey;
echo $_SESSION['RSAPubKey']; //here I send the public key to the client

这是 C# 客户端:

string valasz = RequestPOST(Program.SzerverDomain + "/Teszt1/SZCShost.php", "hostmuv=biztkapcsrsakulcs");

这是“RequestPOST()”方法:

    static CookieContainer cookieJar = new CookieContainer();
public static string RequestPOST(String URL, string postData)
{

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Uri.EscapeUriString(URL));
request.CookieContainer = cookieJar;

var data = Encoding.UTF8.GetBytes(postData);

request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;

using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}

var response = (HttpWebResponse)request.GetResponse();

var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

return responseString.Replace("<br>", "\n").Replace("<br/>", "\n");
}

现在我有了 key ,但我不能使用它们。我试图加载它们,但我在 php 和 C# 中也没有成功。如果你在 C# 中使用了 phpseclib,你能告诉我你的源代码吗?或者你能以其他方式帮助我吗?

谢谢你的好意!

最佳答案

这个解决方案来自neubert的评论:

As is you've posted code that'll get the response from the PHP script and then return it. That said, here's some code: http://csharp-tricks-en.blogspot.de/2015/04/rsa-with-c-and-php.html The phpseclib stuff is out of date - modern versions of phpseclib have built in support for XML keys. But the C# can maybe help you.

我只是把它贴在这里找到它。

This article解释方法。

关于c# - Phpseclib 在 session 中生成 RSA key (使用 C# 客户端),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42177836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com