Home  >  Article  >  Backend Development  >  Share a newly written PHP encryption and decryption function

Share a newly written PHP encryption and decryption function

高洛峰
高洛峰Original
2017-02-09 09:43:462284browse

XOR string encryption method after base64 encryption

Encryption

function encode($str,$key)
{
    $res = base64_encode($str);
    $code = $res^$key;
    return $code;
}

Decryption

function decode($str,$key)
{
    return base64_decode($str^$key);
}

Full code example:

$str = '111021';
$key = 'APPYJJ-PHONE-LAZY';
function encode($str,$key)
{
    $res = base64_encode($str);
    $code = $res^$key;
    return $code;
}
$str = encode($str,$key);
print_r($str);
echo "<hr>";
function decode($str,$key)
{
    return base64_decode($str^$key);
}
print_r(decode($str,$key));
  • The whole program is very simple~ According to logical thinking, it should be difficult to crack, if others don’t know your secret key;

  • If you still feel unsafe. So I’m just going to throw some light here; I suggest you continue to use shift operations in the encryption and decryption process

//加密的时候;
$a = $str >> 4;
//解密的时候则相反
$a = $str << 4;

ok!~ At this point, the blogger continues to work! ~~

XOR string encryption method after base64 encryption

Encryption

function encode($str,$key)
{
    $res = base64_encode($str);
    $code = $res^$key;
    return $code;
}

Decryption

function decode($str,$key)
{
    return base64_decode($str^$key);
}

Complete code example:

$str = '111021';
$key = 'APPYJJ-PHONE-LAZY';
function encode($str,$key)
{
    $res = base64_encode($str);
    $code = $res^$key;
    return $code;
}
$str = encode($str,$key);
print_r($str);
echo "<hr>";
function decode($str,$key)
{
    return base64_decode($str^$key);
}
print_r(decode($str,$key));
  • The whole program is very simple ~ according to logical thinking, it should be difficult to crack, in others Without knowing your secret key;

  • If you still feel unsafe. So I’m going to throw some light here; I suggest you continue to use shift operations in the encryption and decryption process

//加密的时候;
$a = $str >> 4;
//解密的时候则相反
$a = $str << 4;

For more related articles about sharing a newly written PHP encryption and decryption function, please pay attention to PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn