This repository was archived by the owner on Apr 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathDummyModel.php
75 lines (65 loc) · 2.13 KB
/
DummyModel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* tests/Models/DummyModel.php
*
* @package laravel-database-encryption
* @link https://github.com/austinheap/laravel-database-encryption
* @author Austin Heap <me@austinheap.com>
* @version v0.2.1
*/
namespace AustinHeap\Database\Encryption\Tests\Models;
use AustinHeap\Database\Encryption\EncryptionDefaults;
use AustinHeap\Database\Encryption\EncryptionFacade;
use AustinHeap\Database\Encryption\Traits\HasEncryptedAttributes;
use Illuminate\Container\Container;
use Illuminate\Encryption\Encrypter;
use Illuminate\Support\Facades\Facade;
/**
* DummyModel
*/
class DummyModel extends FakeModel
{
use HasEncryptedAttributes;
/** @var array list of attributes that are encrypted */
protected $encrypted = ['encrypt_me'];
/** @var Encrypter */
protected $encrypter;
public function __construct(array $attributes)
{
$this->encrypter = new Encrypter('088409730f085dd15e8e3a7d429dd185', 'AES-256-CBC');
$app = new Container();
$app->singleton('app', 'Illuminate\Container\Container');
$app->singleton('config', 'Illuminate\Config\Repository');
$app['config']->set('database-encryption.prefix', EncryptionDefaults::DEFAULT_PREFIX);
Facade::setFacadeApplication($app);
parent::__construct($attributes);
}
/**
* Return the encrypted value of an attribute's value.
*
* This has been exposed as a public method because it is of some
* use when searching.
*
* @param string $value
*
* @return string
*/
public function encryptedAttribute($value)
{
return EncryptionFacade::getInstance()->buildHeader($value) . $this->encrypter->encrypt($value);
}
/**
* Return the decrypted value of an attribute's encrypted value.
*
* This has been exposed as a public method because it is of some
* use when searching.
*
* @param string $value
*
* @return string
*/
public function decryptedAttribute($value)
{
return $this->encrypter->decrypt(str_replace(EncryptionFacade::getInstance()->buildHeader($value), '', $value));
}
}