• RSA
    1. $private_key = ;
    2. $public_key = ;
    3. $pu_key = openssl_pkey_get_public($public_key);
    4. $pi_key = openssl_pkey_get_private($private_key);
    5. $data = 'hello word';
    6. //公钥加密
    7. openssl_public_encrypt($data, $encrypted, $pu_key);
    8. $encrypted = base64_encode($encrypted);
    9. echo $encrypted,"<br/>";
    10. // 私钥解密
    11. openssl_private_decrypt(base64_decode($encrypted), $decrypted, $pi_key,OPENSSL_PKCS1_OAEP_PADDING);
    12. echo $decrypted;
    • md5

      1. hash('md5', 'hello word', false)
    • sha512

      1. hash('sha512', 'hello word', false)
    • sha384

      1. hash('sha384', 'hello word', false)
    • AES

    1. // $iv 长度必须为16
    2. $method = "AES-128-CBC";
    3. $iv_length = openssl_cipher_iv_length($method);
    4. $iv = openssl_random_pseudo_bytes($iv_length);
    5. // 加密
    6. $encrypted = openssl_encrypt($encrypted, $method, $key, 0, $iv);
    7. // 解密
    8. $decrypted = openssl_decrypt($encrypted, $method, $key, 0,$iv);