Encrypted decryption
Hex (Hex (original + key). GetBytes ("Utf-8")). GetBytes ("Utf-8"))
function String2hex ($string) {
$hex = ';
for ($i =0; $i < strlen ($string); $i + +) {
$hex. = Dechex (Ord ($string [$i]));
}
return $hex;
}
function hex2string ($hex) {
$string = ';
For ($i =0 $i < strlen ($hex)-1; $i +=2) {
$string. = Chr (Hexdec ($hex [$i]. $hex [$i +1]));
}
return $string;
}
Example
$hex = String2hex ("Test sentence ...");
$data = Array (
' AppId ' => ' Shan-guo-chi-bi ',
' Data ' => ' {appId ': ' Shan-guo-chi-bi ', ' cardno ': ' 6006012000000001 '} ',
' Sig ' => ' 4331443139334331313645464642444544364334343742374236364335454243 ',
);
$key = ' 111111111111111111111111 ';
$data [' sig '] = String2hex (Strtoupper (MD5 ($data [' data ']. $key))];
Example
PHP Convert output string to Hex Oct
The following code allows you to change the string of PHP output into 16 and 8.
<?php
$str = "Http://www.111cn.net";
$lixiphp = ";
for ($i = 0; $i < strlen ($STR); $i + +) {
if ($i% 2 = 0) {
$lixiphp. = ' \x '. Base_convert (Ord ($str [$i]), 10, 16);
}
else {
$lixiphp. = ' \ n ' Base_convert (ord ($str [$i]), 10, 8);
}
}
Echo $lixiphp;
?>
Using the code above, convert the string "Http://www.111cn.net" to "\x68\164\x74\160\x3a\57\x2f\142\x6c\157\x67\56\x6c\151\x78\151\x70\150\ X70\56\X63\157\X6D "
PHP implements the base-digit string to convert hexadecimal, and an even-digit string into octal.
The following figure is an ASCII code table that can simply check the relationship between 10, 8, and 16 and 127 commonly used characters.