Avoid using certain characters during encryption in the encoder?

I need to pass the encrypted value through the url. Is there a way to avoid some characters, such as a slash (/) in the value that we get after encryption? Because codeigniter uses a character, such as a slash, to separate parameters in a URL. Please note that I do not want any sentence to pass an encrypted string in the url :)

+3
source share
5 answers

What you want is not encryption (which implies security), but encoding. In practice, your options are basically:

  • urlencode ( , , . , )
  • base64 ( , , , )
  • hex ( , , )

hex. , , , .

-2

PHP urlencode : http://php.net/manual/en/function.urlencode.php urldecode script, GET,

+4
class MY_Encrypt extends CI_Encrypt
{

    function encode($string, $key="", $url_safe=TRUE)
    {
        $ret = parent::encode($string, $key);

        if ($url_safe)
        {
            $ret = strtr(
                    $ret,
                    array(
                        '+' => '.',
                        '=' => '-',
                        '/' => '~'
                    )
                );
        }

        return $ret;
    }


    function decode($string, $key="")
    {
        $string = strtr(
                $string,
                array(
                    '.' => '+',
                    '-' => '=',
                    '~' => '/'
                )
            );

        return parent::decode($string, $key);
    }
}

-

$key = $this->config->item('encryption_key');

$outboundlink = urlencode( $this->encrypt->encode($segment, $key, TRUE) );

$inboundlink  = rawurldecode( $this->encrypt->decode( $segment, $key) );
+4

, hex, 0-9 a-f x.

But I suggest you use TLS (the best SSL) to protect your data, because now you are probably encrypting the data with JS, so that the keys are visible to the attacker.

Do not invoke the current security scheme or encryption, but simply obfuscate.

0
source

this is not the right method, but it can help you a lot. For this, I made several alternative methods.

<html>
<a href="<?= base_url('controller/category/').$this->encrypt->encode($category_men_top->category_id);?>">Category Name</a>
</html>

public function category()
{
    $count=$this->uri->total_segments(); //getting total number of segment 
    $id=''; //assigning value
    for ($i=3; $i<=$count ; $i++) { 
        $id=$id.$this->uri->segment($i).'/';
    }
    $id=rtrim($id,"/"); // removing '/' from the end of the whole string 
    echo "$id";
    echo "<br>";
    echo $this->encrypt->decode($id);
}
-1
source

All Articles