从 PHP 的 COM 的 DOTNET 类调用 RNGCrypto
我试图通过 COM 层从 PHP 调用 RNGCryptoServiceProvider->GetBytes() 。我可以让它连接到类,但是每次调用该方法时,我都会收到两个错误之一(与参数相关)。我认为这与 GetBytes 通过引用获取固定大小的字节数组这一事实有关。由于 PHP 不支持固定大小的字符串,这就是它变得有趣的地方:
错误 1:
$util = new \DOTNET(
'mscorlib',
'System.Security.Cryptography.RNGCryptoServiceProvider'
);
$data = new \Variant(str_repeat(chr(46), $size), VT_UI1 | VT_ARRAY);
$util->GetBytes($data);
错误[0x80070057]参数不正确
由 ->GetBytes()
行抛出。
如果我不使用变体,而仅使用纯字符串,我仍然会收到相同的错误。
但是,如果我传入一个像这样的数组:
$data = array('');
$util->GetBytes($data);
参数0:类型不匹配。
所以我认为变体/字符串方法是正确的(因为它通过了参数类型检查)。但我就是不知道如何让它发挥作用。
public override void GetBytes(
byte[] data
)
谢谢
I'm attempting to call RNGCryptoServiceProvider->GetBytes() from PHP via the COM layer. I can get it to connect to the class, but every time I call the method, I get one of two errors (relating to the parameter). I think it has something to due with the fact that GetBytes takes a fixed size byte array by reference. Since PHP doesn't support fixed sized strings, that's where it gets interesting:
Error 1:
$util = new \DOTNET(
'mscorlib',
'System.Security.Cryptography.RNGCryptoServiceProvider'
);
$data = new \Variant(str_repeat(chr(46), $size), VT_UI1 | VT_ARRAY);
$util->GetBytes($data);
Error [0x80070057] The parameter is incorrect
Which is thrown by the ->GetBytes()
line.
If I don't use a variant, but just use a plain string, I still get the same error.
However, if I pass in an array like so:
$data = array('');
$util->GetBytes($data);
Parameter 0: Type mismatch.
So I think the variant/string approach is the correct one (as it passes the parameter type check). But I just can't figure out how to get it working.
The C# interface to the method is:
public override void GetBytes(
byte[] data
)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我接触 PHP 已经很多年了,更不用说尝试与 .net 互操作了,但是如果您创建一个填充到所需长度的字符串并 unpack() 它会怎么样?
哎呀,浪费了一两个小时玩它却没有结果。我看一下这个:
http://www.sitepoint.com/forums/showthread.php?766246-PHP-and-NET-Secure-RndNum-Generation-using-DOTNET-class
有两个合理的选项 -构建某种简单的包装器,这样您就可以调用无参数方法,或者使用内置的跨平台方法。
It has been years since I touched PHP, let alone tried to interop with .net, but what if you create a string padded to your desired length and unpack() it?
Whelp, wasted an hour or two playing with it to no result. I'd take a look at this:
http://www.sitepoint.com/forums/showthread.php?766246-PHP-and-NET-Secure-RndNum-Generation-using-DOTNET-class
Two reasonable options there - build a simple wrapper of some kind so you can just call a parameterless method, or use something built in and cross-platform.