impl flash.crypto.generateRandomBytes
Opened this issue · 1 comments
GoogleCodeExporter commented
see:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/crypto/
package.html#generateRandomBytes()
signature:
public function generateRandomBytes(numberRandomBytes:uint):ByteArray
under Macintosh / Linux we can use /dev/urandom
$ cat /dev/urandom | LC_CTYPE=C tr -dc 'A-F0-9' | fold -w 2 | sed 1q
in AS3 that would gives
var str:String = Program.open( "cat /dev/urandom | LC_CTYPE=C tr -dc 'A-F0-9' |
fold -w 2 | sed 1q" );
var byte:uint = uint( "0x" + str );
Under Windows we need to use CryptGenRandom()
see PHP implementation of php_win32_get_random_bytes
https://github.com/php/php-src/blob/master/win32/winutil.c#L80
Original issue reported on code.google.com by zwetan
on 8 Mar 2015 at 7:14
GoogleCodeExporter commented
because Program.open() call the CLI as sh -c ""
it is better to do like that
var str:String = Program.open( "LC_CTYPE=C tr -dc 'A-F0-9' < /dev/urandom |
head -c 2" );
shorter command line, less dependencies and no risk to block the CLI and end up
in an infinite loop while running the function, also avoid a carriage return at
end of line
Original comment by zwetan
on 8 Mar 2015 at 7:59