Passed
Push — master ( b0f0bc...e7fcd7 )
by ma
02:00
created

RsaTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
use PHPUnit\Framework\TestCase;
4
use tinymeng\tools\RsaTool;
5
6
class RsaTest extends TestCase
7
{
8
    protected $rsaTool;
9
10
    protected function setUp(): void
11
    {
12
        $this->rsaTool = new RsaTool('./tests/keys');
13
        // 创建公钥和私钥
14
        $this->rsaTool->createKey();
15
    }
16
17
18
    public function testPrivEncryptAndDecrypt()
19
    {
20
        $data = 'Hello, World!';
21
        $encrypted = $this->rsaTool->privEncrypt($data);
22
        $this->assertNotNull($encrypted);
23
24
        $decrypted = $this->rsaTool->privDecrypt($encrypted);
25
        $this->assertEquals($data, $decrypted);
26
    }
27
28
    public function testPubEncryptAndDecrypt()
29
    {
30
        $data = 'Hello, World!';
31
        $encrypted = $this->rsaTool->pubEncrypt($data);
32
        $this->assertNotNull($encrypted);
33
34
        $decrypted = $this->rsaTool->pubDecrypt($encrypted);
35
        $this->assertEquals($data, $decrypted);
36
    }
37
}
38