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