本文整理汇总了PHP中hex2bin函数的典型用法代码示例。如果您正苦于以下问题:PHP hex2bin函数的具体用法?PHP hex2bin怎么用?PHP hex2bin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hex2bin函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prevChar
function prevChar($c)
{
$car = bin2hex($c);
$car = hexdec($car) - 1;
$car = dechex($car);
return hex2bin($car);
}
示例2: get_replay_type
function get_replay_type($data, $fileExtension)
{
if (strcasecmp($fileExtension, "cnc4replay") == 0) {
return "cnc4replay";
}
if (strcasecmp($fileExtension, "ra3replay") == 0) {
return "ra3replay";
}
if (strcasecmp($fileExtension, "kwreplay") == 0) {
return "kwreplay";
}
if (strcasecmp($fileExtension, "cnc3replay") == 0) {
return "cnc3replay";
}
if (strcasecmp($fileExtension, "rep") == 0) {
return "rep";
}
if (strcasecmp($fileExtension, "rec") == 0) {
$hexdata = bin2hex($data);
//先判断是否英雄连,第五个字节后为coh
$cohToken = substr($hexdata, 8, 6);
$cohToken = hex2bin($cohToken);
if ($cohToken == "COH") {
return "rec";
}
//是英雄连
$dowToken = substr($hexdata, 24, 8);
$dowToken = hex2bin($dowToken);
if ($dowToken == "DOW2") {
return "dow2";
}
}
}
示例3: testCompatibility
public function testCompatibility()
{
$h = hex2bin('cfceb8891c58071deedbd1');
$k = 'key123';
$p = 'hello world';
$this->assertEquals($p, Otp::crypt($h, $k));
}
示例4: mta_decode
function mta_decode($headers, $data)
{
$encode_types = get_content_encoding($headers);
$types = explode(',', $encode_types);
$res_data = $data;
foreach ($types as $type) {
if ($type == 'rc4') {
$res_data = mta_rc4($res_data);
} else {
if ($type == 'gzip') {
$header = unpack('Nlength/Lgzip', $res_data);
if (intval($header['gzip']) === 0x88b1f) {
$header = unpack('Nlength/H*body', $res_data);
//$header['ori_buf'] = bin2hex($res_data);
//$header['ori_len'] = strlen($res_data);
$res_data = hex2bin($header['body']);
} else {
}
$res_data = gzdecode($res_data);
//jsondb_logger('nofity', 'gzip log', ['res'=>$res_data,'len'=>strlen($res_data),'header'=>$header]);
}
}
}
if (empty($res_data)) {
jsondb_logger('notify', 'error ' . bin2hex($data));
}
return json_decode($res_data);
}
示例5: decrypt
/**
* Decrypt the given value.
*
* @param string $value
*
* @return string
*/
private function decrypt($value)
{
if ($this->cipher) {
return $this->cipher->decrypt(hex2bin($value));
}
return $value;
}
示例6: testOurSubstrTrailingEmptyStringBugWeird
public function testOurSubstrTrailingEmptyStringBugWeird()
{
$str = hex2bin('4d8ab774261977e13049c42b4996f2c4');
$this->assertSame(16, Core::ourStrlen($str));
if (ini_get('mbstring.func_overload') == 7) {
// This checks that the above hex string is indeed "weird."
// Edit: Er... at least, on PHP 5.6.0 and above it's weird.
// I DON'T KNOW WHY THE LENGTH OF A STRING DEPENDS ON THE VERSION
// OF PHP BUT APPARENTLY IT DOES ¯\_(ツ)_/¯
if (version_compare(phpversion(), '5.6.0', '>=')) {
$this->assertSame(12, strlen($str));
} else {
$this->assertSame(16, strlen($str));
}
} else {
$this->assertSame(16, strlen($str));
// We want ourSubstr to behave identically to substr() in PHP 7 in
// the non-mbstring case. This double checks what that behavior is.
if (version_compare(phpversion(), '7.0.0', '>=')) {
$this->assertSame('', substr('ABC', 3, 0));
$this->assertSame('', substr('ABC', 3));
} else {
// The behavior was changed for PHP 7. It used to be...
$this->assertSame(false, substr('ABC', 3, 0));
$this->assertSame(false, substr('ABC', 3));
}
// Seriously, fuck this shit. Don't use PHP. ╯‵Д′)╯彡┻━┻
}
// This checks that the behavior is indeed the same.
$this->assertSame('', Core::ourSubstr($str, 16));
}
示例7: tagrm_post
function tagrm_post(&$a)
{
if (!local_user()) {
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
}
if (x($_POST, 'submit') && $_POST['submit'] === t('Cancel')) {
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
}
$tag = x($_POST, 'tag') ? hex2bin(notags(trim($_POST['tag']))) : '';
$item = x($_POST, 'item') ? intval($_POST['item']) : 0;
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item), intval(local_user()));
if (!count($r)) {
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
}
$arr = explode(',', $r[0]['tag']);
for ($x = 0; $x < count($arr); $x++) {
if ($arr[$x] === $tag) {
unset($arr[$x]);
break;
}
}
$tag_str = implode(',', $arr);
q("UPDATE `item` SET `tag` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1", dbesc($tag_str), intval($item), intval(local_user()));
info(t('Tag removed') . EOL);
goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
// NOTREACHED
}
示例8: get_peers_blocking
private function get_peers_blocking($info_hash, $host = "router.bittorrent.com", $port = 6881)
{
//create a UDP socket to send commands through
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
//Create Command Packet
$packet = bencode::encode(array("id" => $this->get_unique_node_id(), "info_hash" => hex2bin($info_hash)), array("q" => "get_peers", "t" => $this->unique_id(), "y" => "q"));
socket_sendto($socket, $packet, strlen($packet), 0, $host, $port);
//set timeout
$timeout = array('sec' => 5, 'usec' => 0);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, $timeout);
$time = time();
//recieve data
try {
socket_recvfrom($socket, $buf, 12000, 0, $host, $port);
} catch (Exception $e) {
echo "Error";
return FALSE;
}
//have to manually do the timeout, cant seem to get info from this socket
if (time() - $time >= 4) {
socket_close($socket);
return FALSE;
}
//close socket so bad shit don't happen
socket_close($socket);
return nodeExtract::return_nodes(bencode::decode($buf));
}
示例9: hexToBin
/**
* Hex to bin.
*
* @param string $value hex string
* @return string
*/
public static function hexToBin($value)
{
if (function_exists('hex2bin')) {
return hex2bin($value);
}
return pack("H*", $value);
}
示例10: testPBKDF2
/**
* @covers \Sarciszewski\PHPFuture\Security::pbkdf2()
* ref https://www.ietf.org/rfc/rfc6070.txt
*/
public function testPBKDF2()
{
$a = Future\Security::pbkdf2("sha1", "password", "salt", 2, 20, true);
$this->assertEquals($a, hex2bin('ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957'));
$b = Future\Security::pbkdf2("sha1", "password", "salt", 2, 20, false);
$this->assertEquals($b, 'ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957');
}
示例11: hexToBin
/**
* Custom implementation of hex2bin since the function is only available starting
* with PHP 5.4
*
* @TODO Remove this once 5.3 support for ownCloud is dropped
* @param $message
* @return string
*/
protected static function hexToBin($message)
{
if (function_exists('hex2bin')) {
return hex2bin($message);
}
return pack("H*", $message);
}
示例12: decode_password
/**
* decode_password - decode encoded password to ascii string
* @RA: Request Authenticator passed in from the Access Point
* @encoded: The encoded password
* @secret: Shared secret between node and server
*
* Returns decoded password or FALSE on error
*/
function decode_password($RA, $encoded, $secret)
{
if (strlen($RA) != 32) {
return FALSE;
}
$ra = hex2bin($RA);
if ($ra === FALSE) {
return FALSE;
}
if (strlen($encoded) % 32 != 0) {
return FALSE;
}
$bincoded = hex2bin($encoded);
$password = "";
$last_result = $ra;
for ($i = 0; $i < strlen($bincoded); $i += 16) {
$key = hash('md5', $secret . $last_result, TRUE);
for ($j = 0; $j < 16; $j++) {
$password .= $key[$j] ^ $bincoded[$i + $j];
}
$last_result = substr($bincoded, $i, 16);
}
$j = 0;
for ($i = strlen($password); $i > 0; $i--) {
if ($password[$i - 1] != "") {
break;
} else {
$j++;
}
}
if ($j > 0) {
$password = substr($password, 0, strlen($password) - $j);
}
return $password;
}
示例13: downloadAction
public function downloadAction($name = null)
{
$this->load->helper('download');
$name = hex2bin($name);
$array = $this->_get($name, true);
force_download($name . '.php', $array, true);
}
示例14: decryptPassword
function decryptPassword($input)
{
$config = $GLOBALS['config'];
if ($config['rsa_modulus'] != '' && $config['rsa_exponent'] != '' && $config['rsa_key'] != '' && isset($_SESSION['crypt_key'])) {
if (substr($input, 0, 5) == "enc: ") {
$input = substr($input, 5);
$res = openssl_pkey_get_private($config['rsa_key'], $config['rsa_passphrase']);
openssl_private_decrypt(hex2bin($input), $plaintext, $res);
$plaintext = utf8_encode($plaintext);
//loop through current session login keys and try all of them that haven't expired
foreach ($_SESSION['crypt_key'] as $arrayKey => $key_array) {
//key_array is array(time key was generated, hexadecimal key)
if (time() - $key_array[0] > 5 * 60) {
//delete keys older than 5 minutes
//shouldn't take that long to login anyway!
unset($_SESSION['crypt_key'][$arrayKey]);
} else {
$crypt_key = $key_array[1];
//first part of plaintext should be equal to crypt key
if (substr($plaintext, 0, strlen($crypt_key)) == $crypt_key) {
return substr($plaintext, strlen($crypt_key));
}
}
}
//none of the keys above worked, either forgery or expired form
return "";
} else {
return $input;
}
} else {
return $input;
}
}
示例15: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->prepareExecute($input, $output, $this);
$this->connectMultichain();
$this->multichainDebug($output);
$this->connectMysql();
$documentPath = $input->getArgument("document");
$content = file_get_contents($documentPath);
$hash = hash('sha256', $content);
/** @var Document $ormDocument */
$ormDocument = $this->em->getRepository('Multichain\\Console\\Entity\\Document')->findOneByContent($content);
if ($ormDocument) {
$hex = $ormDocument->getHex();
$transaction = $this->multichain->getRawTransaction($hex, 1);
$data = $transaction["data"][0];
$parsedData = json_decode(hex2bin($data), true);
$originalHash = $parsedData["hash"];
$this->io->text("Submitted document has a hash of <fg=blue>" . $hash . "</fg=blue>");
$this->io->text("Found document the same content in the MySQL database");
if ($hash == $originalHash) {
$this->io->text("Validated the hash found in the database with the Blockchain");
$this->io->success('Hashes match! ' . $documentPath . ' is validated by the Blockchain');
} else {
$this->io->text("Unable to validated the hash found in the database with the Blockchain");
$this->io->error('Hashes do not match! ' . $documentPath . ' is NOT validated by the Blockchain');
}
} else {
$this->io->text("Submitted document has a hash of <fg=blue>" . $hash . "</fg=blue>");
$this->io->text("Found no document with the same content.");
$this->io->error('Hashes do not match! ' . $documentPath . ' is NOT validated by the Blockchain');
}
}