Produces string of random byte of given length.
public static randomBytes ( integer $len ) : string | ||
$len | integer | length of requested string |
리턴 | string | RAW random binary string |
/** * Generates a secret key for given hash function, returns RAW key or false * if function is not supported * * @param string $func hash function (sha1 or sha256) * @return mixed */ protected function _genSecret($func) { if ($func == 'sha1') { $macLen = 20; /* 160 bit */ } else { if ($func == 'sha256') { $macLen = 32; /* 256 bit */ } else { return false; } } return Zend_OpenId::randomBytes($macLen); }
/** * testing testRedirect * */ public function testRandomBytes() { $this->assertSame( '', Zend_OpenId::randomBytes(0) ); $x = Zend_OpenId::randomBytes(1); $this->assertTrue( is_string($x) ); $this->assertSame( 1, strlen($x) ); $x = Zend_OpenId::randomBytes(1024); $this->assertTrue( is_string($x) ); $this->assertSame( 1024, strlen($x) ); }