【问题标题】:enciphered URLs laravel加密 URLs laravel
【发布时间】:2021-11-20 21:30:50
【问题描述】:

如何使加密的字符更短?

\Crypt::encrypt($event->id))

结果:

http://myurl/id/eyJpdiI6Im5ub0hyaWJwVE1iendYbHNaSzJsSXc9PSIsInZhbHVlIjoiVHhpNmF4b3NlQjk2NFluRXhCOFZuQT09IiwibWFjIjoiZDkxNzk2OTlmZGRmZWJjYjFlNjExYjcyNWU4Y2Y4NWYwMjYxMTkxN2ZmNzU3NGM4Nzg0OWJkNjk1NmExNjVkZiIsInRhZyI6IiJ9

生成一个非常大的链接,我需要缩短它,可以吗?

【问题讨论】:

    标签: php laravel laravel-5 laravel-8


    【解决方案1】:

    有很多方法可以做到,我将向您展示一些PHP函数,希望对您有所帮助

    <?php
    $data= "Password";
    $md5 = md5($data); // https://www.php.net/manual/en/function.md5.php
    $sha1 = sha1($data); // https://www.php.net/manual/en/function.sha1.php
    $hash = hash('gost',$data); // https://www.php.net/manual/en/function.hash.php
    $crypt = crypt($data); // https://www.php.net/manual/en/function.crypt.php
    
    
    echo "md5: " . $md5 . "<br>";
    echo "sha1: " . $sha1 . "<br>";
    echo "hash: " . $hash . "<br>";
    echo "crypt: " . $crypt . "<br>";
    echo hash_equals($crypt, crypt("Password", $crypt)); // For check if hashed data by "ctypt" equal to input
    
    

    输出

    // I think there are smaller as you want
    md5: dc647eb65e6711e155375218212b3964
    sha1: 8be3c943b1609fffbfc51aad666d0a04adf83c9d
    hash: 243674170a09e1e5fc9aafae4ba426841efc9ad55a5c013d1277f204e3ecfa04
    crypt: $1$3yXFeq2Y$YCALetipqV22Cc1sH9YYk.
    1
    

    您应该添加一些盐以使您的数据更强大

    $data = "Password";
    $salt = "g5s46df1s65df1s65d";
    $sha1 = sha1($data.$salt);
    echo "sha1: " . $sha1 . "<br>";
    

    很难获得清晰的数据,因为攻击者需要知道盐

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-30
      • 2018-05-27
      • 1970-01-01
      • 2023-04-05
      • 2019-01-24
      • 1970-01-01
      • 1970-01-01
      • 2018-10-27
      相关资源
      最近更新 更多