I notice I had exactly 2 equal signs at the end of my encrypted string too. It seems theres always 2 equal signs at the end. Here's my solution
function encryptString($string, $action, $baseIP = 'false', $extraKey = ''){
    global $flag;
    $encryptedIP = '';
    if($baseIP){
        $encryptedIP = encryptString($_SERVER['REMOTE_ADDR'], 'encrypt', false);
    }
    $output = false;
    $encrypt_method = "AES-256-CBC";
    $secret_key = $flag['2nd-encrypt-key'].$encryptedIP.'-'.$extraKey;
    $secret_iv = $flag['2nd-encrypt-secret'].$encryptedIP.'-'.$extraKey;
    $key = hash('sha256', $secret_key);
    $iv = substr(hash('sha256', $secret_iv), 0, 16);
    $output;
    if($action == 'encrypt'){
        $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
        $output = base64_encode($output);
        //replace equal signs with char that hopefully won't show up
        $output = str_replace('=', '[equal]', $output);
    }else if($action == 'decrypt'){
        //put back equal signs where your custom var is
        $setString = str_replace('[equal]', '=', $string);
        $output = openssl_decrypt(base64_decode($setString), $encrypt_method, $key, 0, $iv);
    }
    return $output;
}