Esempio n. 1
0
 /**
  * Tests the conversion of a hexadecimal string into a signed integer.
  *
  * @dataProvider hexToSignedIntProvider
  * @covers hexToSignedInt
  *
  * @param string $hex a hexadecimal string
  * @param int $res the resulting signed integer
  */
 public function testHexToSignedInt($hex, $res)
 {
     $this->assertSame($res, Math::hexToSignedInt($hex));
 }
 /**
  * Provides test data for the hash calculation test.
  *
  * @return array the test data
  */
 public function calculateHMACProvider()
 {
     $res = array();
     $res[] = array(Math::hexToString('4869205468657265'), Math::hexToString('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'), 'b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7');
     $res[] = array(Math::hexToString('7768617420646f2079612077616e7420666f72206e6f7468696e673f'), Math::hexToString('4a656665'), '5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843');
     return $res;
 }
Esempio n. 3
0
 public function calculatePasswordHash($password, $iterations, $hmacKey)
 {
     // Calculate salt
     $salt = Math::getRandomHexString(static::BCRYPT_SALT_LENGTH);
     $salt = $this->buildCryptSalt($salt, $iterations);
     // Calculate bcrypt
     $hash = crypt($password, $salt);
     // Build return string
     $args = base64_encode($hash) . self::SEGMENT_SEPARATOR . base64_encode($salt);
     $hmac = $this->calculateHMAC($args, $hmacKey);
     return $args . self::SEGMENT_SEPARATOR . base64_encode($hmac);
 }
Esempio n. 4
0
 public function buildCryptSalt($salt, $iterations)
 {
     return '$6$rounds=' . Math::clip($iterations, 1000, 999999999) . '$' . $salt;
 }
Esempio n. 5
0
 /**
  * Provides test data for the hash calculation test.
  *
  * @return array the test data
  */
 public function calculateHMACProvider()
 {
     $res = array();
     $res[] = array(Math::hexToString(''), Math::hexToString(''), '74e6f7298a9c2d168935f58c001bad88');
     $res[] = array('The quick brown fox jumps over the lazy dog', 'key', '80070713463e7749b90c2dc24911e275');
     return $res;
 }
 /**
  * Tests creating the key.
  *
  * @covers empire\framework\crypto\symmetric\cyphers\Aes256SymmetricCypher::createKey
  */
 public function testCreateKey()
 {
     $this->assertTrue((bool) preg_match('#^[A-F0-9]{32}$#', Math::stringToHex($this->cypher->createKey())));
 }
Esempio n. 7
0
 /**
  * Returns a session ID.
  *
  * @return string the session ID
  */
 private function createSID()
 {
     return Math::getRandomHexString(64);
 }
 public function createKey()
 {
     return pack('H*', Math::getRandomHexString($this->getKeySize()));
 }
Esempio n. 9
0
 /**
  * Decodes a GID string and outputs the results as array.
  *
  * @param string $gid the GID to parse
  * @return array boolean array with indices <code>type</code>, <code>crc32Name</code>,
  * <code>localID</code> and <code>uniqueID</code> for the GID type, CRC32 of name (hexadecimal),
  * local ID and unique ID or <code>false</code> if the GID string is malformed
  */
 public function decode($gid)
 {
     if (!preg_match('#^[0-9a-f]{32}$#', $gid)) {
         return false;
     }
     $res = array();
     $res['type'] = (int) hexdec($gid[0]);
     $res['crc32Name'] = ltrim(substr($gid, 1, 8), '0');
     if (empty($res['crc32Name'])) {
         $res['crc32Name'] = '0';
     }
     $res['localID'] = Math::hexToSignedInt(ltrim(substr($gid, 9, 8), '0'));
     $res['uniqueID'] = ltrim(substr($gid, 17, 13), '0');
     return $res;
 }
 /**
  * Provides test data for the hash calculation test.
  *
  * @return array the test data
  */
 public function calculateHMACProvider()
 {
     $res = array();
     $res[] = array(Math::hexToString('4869205468657265'), Math::hexToString('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'), '87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854');
     $res[] = array(Math::hexToString('7768617420646f2079612077616e7420666f72206e6f7468696e673f'), Math::hexToString('4a656665'), '164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737');
     return $res;
 }