Skip to content

whereEncryptedIn functionality #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gulimshah opened this issue Jan 23, 2022 · 0 comments
Open

whereEncryptedIn functionality #16

gulimshah opened this issue Jan 23, 2022 · 0 comments

Comments

@gulimshah
Copy link

As built in functions of laravel like where(), orWhere() clauses, whereIn() clause may also be added into package.
Here is some of my dirty way which is working

Function added to file at EncryptionEloquentBuilder class

    public function whereEncryptedIn($param1, Array $param2)
    {
      $filter            = new \stdClass();
      $filter->field     = $param1;
      $filter->operation = 'In';
      $stringValues = array_map('strval', $param2 );
      $valuesWithBrace = json_encode($stringValues);
      $singleReplace = str_replace("[","(",$valuesWithBrace);
      $filter->values = str_replace("]",")",$singleReplace);
      $salt = substr(hash('sha256', env('APP_KEY')), 0, 16);
      return self::whereRaw("CONVERT(AES_DECRYPT(FROM_bASE64(`{$filter->field}`), '{$salt}') USING utf8mb4) {$filter->operation} 
      {$filter->values} ");
    `}` 

and after that it can be use like whereEncryptedIn()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant