randomBytes() 공개 정적인 메소드

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
예제 #1
0
 /**
  * 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);
 }
예제 #2
0
 /**
  * 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) );
 }