我需要通过URL来传递一些加密值。 有没有办法避免,我们加密后得到的值的某些字符,如斜杠(/)? 因为在笨,字符,如斜线用于在URL分离参数。 请注意,我不希望任何建议,不经过加密的字符串中的URL :)
Answer 1:
你想要的是不是一个加密(这意味着安全性),但编码。 在实践中,你的选择基本上是:
- 进行urlencode(如果你希望字符串是有点清晰使用此功能。这也将让您比其他两个选项一个较短的字符串)
- BASE64(使用这个,如果你不希望字符串清晰可辨,并希望在您的字符串以节省空间)
- 十六进制 (使用这个,如果你不希望字符串清晰可辨,你不关心字符串长度)
我不会选择十六进制。 决定是否希望字符串清晰可辨,并挑选了两个第一之一。
Answer 2:
使用PHP urlencode
函数加密后: http://php.net/manual/en/function.urlencode.php和使用urldecode
在多数民众赞成在处理GET数据的脚本。
Answer 3:
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) );
Answer 4:
一种想法是表示仅使用0-9和AF和任选X加密的字符串作为十六进制。
但我建议你使用TLS(SSL更好)保护您的数据,因为现在你可能使用JS所以键是攻击者看到加密的数据。
别叫当前方案的安全性或加密,但只是模糊。
Answer 5:
这不是正确的方法,但它可以帮助你很多。 我也做了一些这方面的交流方法。
<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);
}
文章来源: Avoid specific characters while encrypting in codeigniter?