0
私は、セッションIDを使用してファイルのIDを暗号化し、ダウンロード用の一時URLとして使用する方法を探しています。Laravel 5.4セッションIDによる暗号化
私はちょうどencrypt
の機能をLaravelで見つけましたが、それは私が欲しいものではありません。エンコードとデコードにセッションID文字列を使用できる同様の機能はありますか?
私は、セッションIDを使用してファイルのIDを暗号化し、ダウンロード用の一時URLとして使用する方法を探しています。Laravel 5.4セッションIDによる暗号化
私はちょうどencrypt
の機能をLaravelで見つけましたが、それは私が欲しいものではありません。エンコードとデコードにセッションID文字列を使用できる同様の機能はありますか?
make function in
**Path - /app/Libraries/Scramble.php**
**<Scramble.php>**
<?php
namespace App\Libraries;
use Crypt;
use Session;
use Illuminate\Contracts\Encryption\EncryptException;
class Scramble
{
public function __construct()
{
}
/**
* Encrypt the given value with session binding.
*
* @param string $value
*
* @return string
*
* @throws \Illuminate\Contracts\Encryption\EncryptException
*/
public static function encrypt($value)
{
if ($value === false) {
throw new EncryptException('Could not encrypt the data.');
}
$manupulate_val = Session::getId()."##".config('app.key')."##".$value;
return Crypt::encrypt($manupulate_val);
}
/**
* Decrypt the given value.
*
* @param string $decrypted
* @return string
*
* @throws \Illuminate\Contracts\Encryption\DecryptException
*/
public static function decrypt($decrypted)
{
if ($decrypted === false) {
throw new DecryptException('Could not decrypt the data.');
}
$sess_id = Session::getId();
$decryptedStr = Crypt::decrypt($decrypted);
$decryptedStrArr = explode("##", $decryptedStr);
if (is_array($decryptedStrArr) && $decryptedStrArr['0'] !== $sess_id) {
abort(400);
}
if (is_array($decryptedStrArr) && $decryptedStrArr['1'] !== config('app.key')) {
abort(400);
}
return $decryptedStrArr['2'];
}
}
**</scramble.php>**
now you can call anywhere....
use App\Libraries\Scramble;
$Yourid = 12345;
$sessionIdWithencData = Scramble::encrypt($Yourid);
$sessionIdWithdecData = Scramble::decrypt($sessionIdWithencData);
dd($sessionIdWithdecData);
==========================================
i hope this is help full
ここはまさにあなたのためhttp://laravel-recipes.com/recipes/105/encrypting-a-value –
ないのはなぜ 'encrypt'作業代替の方法ですか?後で復号化で取り出すことができる文字列を暗号化します。 '暗号化する'ことができないことをあなたがここで何をしているのですか? – user3158900
私はCrypt :: setKey()を使うべきですか?しかし、それはアプリ全体のキーを置き換えるでしょうか?それは何かを壊すことができる – fiter