You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB
PHP

<?php
namespace App\Libs;
trait EncryptQuery
{
// 암호값을 고정하기 위함
private $iv = 'FIXED_ENCRYPT_ST';
public function scopeWhereCompareCrypt($query, $field, $compare, $value)
{
return $query->where($field, $compare, $this->encrypt($value));
}
public function scopeWhereCrypt($query, $field, $value)
{
return $query->where($field, $this->encrypt($value));
}
public function scopeOrWhereCrypt($query, $field, $value)
{
return $query->orWhere($field, $this->encrypt($value));
}
public function scopeWhereInCrypt($query, $field, $values)
{
$ins = [];
foreach ($values as $value) {
$ins[] = $this->encrypt($value);
}
return $query->whereIn($field, $ins);
}
public function encrypt($value)
{
return base64_encode(openssl_encrypt($value, "AES-256-CBC", config('app.key'), 0, $this->iv));
}
public function decrypt($value)
{
return openssl_decrypt(base64_decode($value), "AES-256-CBC", config('app.key'), 0, $this->iv);
}
}