Skip to content
Snippets Groups Projects
Commit e1bb1b81 authored by Olav Morken's avatar Olav Morken
Browse files

Utilities: Added stringToHex function and changed generateID to use this.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@550 44740490-163a-0410-bde0-09ae8108e29a
parent b39259ca
No related branches found
No related tags found
No related merge requests found
......@@ -177,12 +177,7 @@ class SimpleSAML_Utilities {
}
public static function generateID() {
$bytes = self::generateRandomBytes(21);
$key = '_';
for($i = 0; $i < 21; $i++) {
$key .= sprintf('%02x', ord($bytes[$i]));
}
return $key;
return '_' . self::stringToHex(self::generateRandomBytes(21));
}
......@@ -917,6 +912,21 @@ class SimpleSAML_Utilities {
return $data;
}
/**
* This function converts a binary string to hexadecimal characters.
*
* @param $bytes Input string.
* @return String with lowercase hexadecimal characters.
*/
public function stringToHex($bytes) {
$ret = '';
for($i = 0; $i < strlen($bytes); $i++) {
$ret .= sprintf('%02x', ord($bytes[$i]));
}
return $ret;
}
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment