回答編集履歴
1
追記
test
CHANGED
@@ -6,6 +6,48 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
+
```php
|
10
|
+
|
11
|
+
/**
|
12
|
+
|
13
|
+
* Encrypt with shared password.
|
14
|
+
|
15
|
+
*
|
16
|
+
|
17
|
+
* @param string $data
|
18
|
+
|
19
|
+
* @param string $password
|
20
|
+
|
21
|
+
* @return string Binary string.
|
22
|
+
|
23
|
+
*/
|
24
|
+
|
25
|
+
public function encrypt(string $data, string $password): string
|
26
|
+
|
27
|
+
{
|
28
|
+
|
29
|
+
$iv = $this->random($this->length);
|
30
|
+
|
31
|
+
$encrypted = openssl_encrypt($data, $this->method, $password, OPENSSL_RAW_DATA, $iv);
|
32
|
+
|
33
|
+
if ($encrypted === false) {
|
34
|
+
|
35
|
+
// @codeCoverageIgnoreStart
|
36
|
+
|
37
|
+
throw new EncryptionFailedException(openssl_error_string());
|
38
|
+
|
39
|
+
// @codeCoverageIgnoreEnd
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
return "$iv$encrypted";
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
|
50
|
+
|
9
51
|
Laravel だと署名もつけてもう少し丁寧にやってますね。
|
10
52
|
|
11
53
|
|