php aes加密

aes是一种对称加密 加密解密使用的都是同一个密钥
像ssl用的都是非对称加密 用公钥去加密,用私钥才可以解密
在某些场景,我们需要对数据进行简单的加密传输

function encrypt($input, $key){
    $data = base64_encode(openssl_encrypt($input, 'AES-128-ECB', $key, OPENSSL_RAW_DATA));
       return $data;
}
function decrypt($str, $key){
    $decrypted = openssl_decrypt(base64_decode($str), 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
    return $decrypted;
}
echo encrypt("111",'密码');
echo decrypt("4OcwR3JfIY/b36lmI2/AKg==",'密码');
Last modification:December 24th, 2019 at 03:31 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment

简爱博客