RSAEncrypt::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * @link https://github.com/phpviet/omnipay-momo
4
 * @copyright (c) PHP Viet
5
 * @license [MIT](http://www.opensource.org/licenses/MIT)
6
 */
7
8
namespace Omnipay\MoMo\Support;
9
10
/**
11
 * @author Vuong Minh <[email protected]>
12
 * @since 1.0.0
13
 */
14
class RSAEncrypt
15
{
16
    /**
17
     * Khóa dùng để mã hóa dữ liệu.
18
     *
19
     * @var string
20
     */
21
    protected $publicKey;
22
23
    /**
24
     * Khởi tạo đối tượng DataEncrypt.
25
     *
26
     * @param  string  $publicKey
27
     */
28
    public function __construct(string $publicKey)
29
    {
30
        $this->publicKey = $publicKey;
31
    }
32
33
    /**
34
     * Trả về chuỗi mã hóa của dữ liệu truyền vào.
35
     *
36
     * @param  array  $data
37
     * @return string
38
     */
39
    public function encrypt(array $data): string
40
    {
41
        $data = json_encode($data);
42
        openssl_public_encrypt($data, $dataEncrypted, $this->publicKey, OPENSSL_PKCS1_PADDING);
43
44
        return base64_encode($dataEncrypted);
45
    }
46
}
47