使用PHP SoapClient将加密值传递到.Net SOAP服务的问题 [英] Problems using PHP SoapClient to pass an encrypted value to a .Net SOAP service

查看:205
本文介绍了使用PHP SoapClient将加密值传递到.Net SOAP服务的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SOAP服务我正在调用PHP 5.3.1的内置SoapClient。我必须对服务执行的第一个操作是自定义身份验证操作,并且必须传递的必需参数之一是我使用PHP的mcrypt创建的3DES加密字符串,如下所示:

I have a SOAP service I am calling with PHP 5.3.1's builtin SoapClient. The first operation I must perform on the service is a custom authentication operation, and one of the required parameters I must pass is a 3DES encrypted string which I am creating using PHP's mcrypt, like so:

$encryptionKey        = '1234myKey1234';
$currentFormattedDate = date ("Y/m/d H:i");
$encryptedString      = mcrypt_encrypt('tripledes', $encryptionKey, $currentFormattedDate, 'ecb');



如果我尝试只传递 $ encryptedString 因为我从 mcrypt_encrypt()得到它我在我身边遇到致命错误,并且没有调用:

If I try to just pass $encryptedString as I get it from mcrypt_encrypt() I get a fatal error on my side and no call is made:


致命错误:SOAP-ERROR:Encoding:string'd\xe0 ...'不是/ path / to / file中的有效utf-8字符串

Fatal error: SOAP-ERROR: Encoding: string 'd\xe0...' is not a valid utf-8 string in /path/to/file

但是如果我 utf8_encode()这样的字符串:

However if I utf8_encode() the string as such:

$encryptedString = utf8_encode($encryptedString)

则会发出调用,但其网络服务会以下列错误做出响应:

Then the call is made but their webservice responds with the following error:


格式化程序在尝试反序列化消息:尝试反序列化参数 http://tempuri.org/:argStatusDate 时出错。 InnerException消息是'有一个错误反序列化类型System.String的对象。字节0x19在此位置无效。第2行,位置318。

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:argStatusDate. The InnerException message was 'There was an error deserializing the object of type System.String. The byte 0x19 is not valid at this location. Line 2, position 318.'.

这是最接近我可以得到的成功与这个过程,在尝试了这么多的事情,我回到广场之一。我已经验证我可以只传递一个假的字符串,导致预期的响应无法验证。

This is the closest I can get to success with this process after having tried so many things that I'm back to square one. I have verified I can just pass a bogus string which results in the expected response of not being able to authenticate.

我不认为这应该有什么区别,因为我相信SOAP调用最终是作为utf8,但我已经尝试设置'encoding'=>'ISO-8859-1'时构建我的SoapClient在PHP中,我得到相同的错误。

I don't think this should make any difference since I believe the SOAP call is ultimately made as utf8, but I have tried setting 'encoding' => 'ISO-8859-1' when constructing my SoapClient in PHP and I get the same error. The call is made but the server responds with the deserialization error.

有人知道一个更好的方法来处理这个加密的字符串,这将使我的PHP客户端和他们的.Net webservice?

Does anyone know a better way for me to treat this encrypted string that will please both my PHP client and their .Net webservice?

也许问题是他们的结束?

Maybe the problem is on their end?

FWIW,我也可以要求我们根据其文档将加密方法更改为Rijndael AES Block Cypher。

FWIW, I can also request that we change the encryption method to "Rijndael AES Block Cypher" per their documentation. Not sure if that would result in an easier to handle string.

推荐答案

您可能需要对基本64位编码的数据进行编码CDATA段内的开始和结束标签。您可能想要向服务创建者提供样本,或者 - 如果是网络服务 - 尝试下载定义,甚至创建客户端通过发现。注意,最后一个链接是使用Google搜索找到的,我已经退出了PHP一段时间。

You probably need to encode the data in a base 64 encoded CDATA segment inside the opening and closing tags. You might want to ask the creater of the service for a sample, or - if it is a webservice - try to download the definition or even create a client through discovery. Note that the last link was found using Google search, I've been out of PHP for a while.

更改密码不会有帮助,虽然任何东西比ECB编码XML

changing the cipher won't help for this, although anything is better than ECB encoding XML

这篇关于使用PHP SoapClient将加密值传递到.Net SOAP服务的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆