본문 바로가기
웹 개발 이야기/php

[PHP] 암호화 복호화

by Gommin 2023. 7. 4.
function set_encrypt($str)
{
    $secret_key = "123456789";
    $secret_iv = "#@$%^&*()_+=-";
    $key = hash('sha256', $secret_key);
    $iv = substr(hash('sha256', $secret_iv), 0, 32)    ;
    return str_replace("=", "", base64_encode(
            openssl_encrypt($str, "AES-256-CBC", $key, 0, $iv))
    );
}

function set_decrypt($str)
{
    $secret_key = "123456789";
    $secret_iv = "#@$%^&*()_+=-";
    $key = hash('sha256', $secret_key);
    $iv = substr(hash('sha256', $secret_iv), 0, 32);
    return openssl_decrypt(
        base64_decode($str), "AES-256-CBC", $key, 0, $iv
    );
}

댓글