RNGCrypto call from COM DOTNET class from PHP

I am trying to call RNGCryptoServiceProvider-> GetBytes () from PHP through the COM level. I can connect it to the class, but every time I call the method, I get one of two errors (related to the parameter). I think this is because GetBytes accepts an array of bytes with a fixed size by reference. Since PHP does not support fixed-size strings, which is 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] Invalid parameter

What is selected by the line ->GetBytes() .

If I do not use the option, but just use a simple string, I still get the same error.

However, if I pass the array this way:

 $data = array(''); $util->GetBytes($data); 

Parameter 0: type mismatch.

So, I think the option / string approach is correct (since it passes the type check of the parameter). But I just can't figure out how to make it work.

C # interface for the method :

 public override void GetBytes( byte[] data ) 

thanks

+6
source share
1 answer

It has been many years since I touched PHP, not to mention trying to interact with .net, but what if you create a line filled with the desired length and unpack ()?

 $byte_array = unpack('C*', '12345678'); $util->GetBytes($byte_array); 

Whelp wasted an hour or two playing with him, with no results. I would look at this:

http://www.sitepoint.com/forums/showthread.php?766246-PHP-and-NET-Secure-RndNum-Generation-using-DOTNET-class

There are two reasonable options - create a simple wrapper so that you can simply call the method without parameters or use something built-in and cross-platform.

+3
source

Source: https://habr.com/ru/post/891486/


All Articles