Encryption PHP algorithm
Recent project requirements require PHP to be used to generate an encrypted string from some ordinary information through an encryption algorithm. The encrypted string can parse out the previous information through the decryption algorithm (reverse). Since I have never done it before, I would like to ask friends here if they have any ideas for ready-made encryption and decryption algorithms. The algorithm needs to be complex enough and not easy to be cracked. It would be better if there is a specific code
http://blog.shiniv.com/2013/11/use-aes-encryption-algorithm-to-encrypt-data-in-php/
http://www.soso.io/article/32937.html
Commonly used encryption/decryption string functions:
/**
$lockstream = 'st=lDEFABCNOPyzghi_jQRST-UwxkVWXYZabcdef IJK6/7nopqr89LMmGH012345uv';
//Find a random number and find a secret lock value from the secret lock string
$lockLen = strlen($lockstream);
$lockCount = rand(0,$lockLen-1);
$randomLock = $lockstream[$lockCount];
//Combined with the random encryption value to generate the MD5 password
$password = md5($password.$randomLock);
//Start encrypting the string
$txtStream = base64_encode($txtStream);
$tmpStream = '';
$i=0;$j=0;$k = 0;
for ($i=0; $i
$j = (strpos($lockstream,$txtStream[$i]) $lockCount ord($password[$k]))%($lockLen);
$tmpStream .= $lockstream[$j];
$k ;
}
return $tmpStream.$randomLock;
}
header("content-type:text/html;charset=utf8");
$str = "My name is Jack Ma and I won’t tell anyone else!"; //Encrypted content
$key = "9545646"; //Key. Make your own key
$cipher = MCRYPT_DES; //Password type
$modes = MCRYPT_MODE_ECB; //Password mode
$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher,$modes),MCRYPT_RAND);//Initialization vector
echo "Encrypted plain text: ".$str."
";
$str_encrypt =base64_encode( mcrypt_encrypt($cipher,$key,$str,$modes,$iv)); //Encryption function
echo "Encrypted ciphertext: ".$str_encrypt."
";
$str_decrypt = mcrypt_decrypt($cipher,$key,base64_decode($str_encrypt),$modes,$iv); //Decryption function
echo "Restore:".$str_decrypt;
?>