【问题标题】:How to en/decrypt C# to PHP/Soap client/server communication using AES256如何使用 AES256 将 C# 加密/解密到 PHP/Soap 客户端/服务器通信
【发布时间】:2018-10-28 14:02:41
【问题描述】:

我正在尝试使用此库加密 C# 客户端和 PHP/nuSOAP 服务器之间的通信:https://github.com/mervick/aes-everywhere/

当我在客户端/服务器内部加密然后解密时,一切正常。

当客户端/服务器之间没有加密时,一切都会正常运行。

但是,当我尝试加密、发送和解密数据时,我得到 System.InvalidOperationException: Response is not well-formed XML。怎么会?

C#代码:

try
{

    AES spymaster = new AES();
    string key = "admin";
    string encrypted = spymaster.Encrypt(XMLString, key);
    MyOutString = MyServer.test(encrypted);
}
catch (Exception e)
{
    MessageBox.Show(e.ToString());
}

PHP 代码:

     $server->register( 'test', array('$mystring' => 'xsd:instring'),     array('return'=>'xsd:string'), "http://mujserver.cz", false, 'rpc', 'encoded', 'Ignore this description too late oups');


     function test ($mystring) 
     {

             $key = "admin";
             $result = AES256::decrypt($myXMLstring, $key);

             return $result;
     }

编辑:删除描述以免混淆。

【问题讨论】:

  • 您的 php 代码看起来像是在将 xml 转换为 json
  • 是的,这就是以后的意图。现在我正在尝试做加密/解密位。我删除了令人困惑的描述。

标签: c# php encryption aes nusoap


【解决方案1】:

我通过先将数据转换为byte[],然后发送来解决它!

C#中的相关函数

byte[] System.Text.Encoding.UTF8.GetBytes(string);
string System.Text.Encoding.UTF8.GetString(byte[]);

PHP中的相关函数:

string hex2bin ( string $data )
string bin2hex ( string $str )

pack()、unpack() 也可以!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-29
    • 1970-01-01
    • 2020-04-16
    • 1970-01-01
    • 2014-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多