@@ 28-49 (lines=22) @@ | ||
25 | /** |
|
26 | * @package Limoncello\Crypt |
|
27 | */ |
|
28 | class PrivateKeyAsymmetricDecrypt extends BasePrivateKeyAsymmetricCrypt implements DecryptInterface |
|
29 | { |
|
30 | /** |
|
31 | * @inheritdoc |
|
32 | */ |
|
33 | public function decrypt(string $data): string |
|
34 | { |
|
35 | $result = null; |
|
36 | $decryptChunkSize = $this->getDecryptChunkSize(); |
|
37 | if ($decryptChunkSize !== null) { |
|
38 | $key = $this->getKey(); |
|
39 | $this->clearErrors(); |
|
40 | foreach ($this->chunkString($data, $decryptChunkSize) as $chunk) { |
|
41 | $retVal = openssl_private_decrypt($chunk, $decrypted, $key); |
|
42 | $retVal === true ?: $this->throwException(new CryptException($this->getErrorMessage())); |
|
43 | $result .= $decrypted; |
|
44 | } |
|
45 | } |
|
46 | ||
47 | return $result; |
|
48 | } |
|
49 | } |
|
50 |
@@ 28-49 (lines=22) @@ | ||
25 | /** |
|
26 | * @package Limoncello\Crypt |
|
27 | */ |
|
28 | class PrivateKeyAsymmetricEncrypt extends BasePrivateKeyAsymmetricCrypt implements EncryptInterface |
|
29 | { |
|
30 | /** |
|
31 | * @inheritdoc |
|
32 | */ |
|
33 | public function encrypt(string $data): string |
|
34 | { |
|
35 | $result = null; |
|
36 | $encryptChunkSize = $this->getEncryptChunkSize(); |
|
37 | if ($encryptChunkSize !== null) { |
|
38 | $key = $this->getKey(); |
|
39 | $this->clearErrors(); |
|
40 | foreach ($this->chunkString($data, $encryptChunkSize) as $chunk) { |
|
41 | $retVal = openssl_private_encrypt($chunk, $encrypted, $key); |
|
42 | $retVal === true ?: $this->throwException(new CryptException($this->getErrorMessage())); |
|
43 | $result .= $encrypted; |
|
44 | } |
|
45 | } |
|
46 | ||
47 | return $result; |
|
48 | } |
|
49 | } |
|
50 |
@@ 28-49 (lines=22) @@ | ||
25 | /** |
|
26 | * @package Limoncello\Crypt |
|
27 | */ |
|
28 | class PublicKeyAsymmetricDecrypt extends BasePublicKeyAsymmetricCrypt implements DecryptInterface |
|
29 | { |
|
30 | /** |
|
31 | * @inheritdoc |
|
32 | */ |
|
33 | public function decrypt(string $data): string |
|
34 | { |
|
35 | $result = null; |
|
36 | $decryptChunkSize = $this->getDecryptChunkSize(); |
|
37 | if ($decryptChunkSize !== null) { |
|
38 | $key = $this->getKey(); |
|
39 | $this->clearErrors(); |
|
40 | foreach ($this->chunkString($data, $decryptChunkSize) as $chunk) { |
|
41 | $retVal = openssl_public_decrypt($chunk, $decrypted, $key); |
|
42 | $retVal === true ?: $this->throwException(new CryptException($this->getErrorMessage())); |
|
43 | $result .= $decrypted; |
|
44 | } |
|
45 | } |
|
46 | ||
47 | return $result; |
|
48 | } |
|
49 | } |
|
50 |
@@ 28-49 (lines=22) @@ | ||
25 | /** |
|
26 | * @package Limoncello\Crypt |
|
27 | */ |
|
28 | class PublicKeyAsymmetricEncrypt extends BasePublicKeyAsymmetricCrypt implements EncryptInterface |
|
29 | { |
|
30 | /** |
|
31 | * @inheritdoc |
|
32 | */ |
|
33 | public function encrypt(string $data): string |
|
34 | { |
|
35 | $result = null; |
|
36 | $encryptChunkSize = $this->getEncryptChunkSize(); |
|
37 | if ($encryptChunkSize !== null) { |
|
38 | $key = $this->getKey(); |
|
39 | $this->clearErrors(); |
|
40 | foreach ($this->chunkString($data, $encryptChunkSize) as $chunk) { |
|
41 | $retVal = openssl_public_encrypt($chunk, $encrypted, $key); |
|
42 | $retVal === true ?: $this->throwException(new CryptException($this->getErrorMessage())); |
|
43 | $result .= $encrypted; |
|
44 | } |
|
45 | } |
|
46 | ||
47 | return $result; |
|
48 | } |
|
49 | } |
|
50 |