|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* The digital envelope data object. |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace CryptoManana\DataStructures; |
|
8
|
|
|
|
|
9
|
|
|
use \CryptoManana\Core\Abstractions\DataStructures\AbstractBasicStructure as BasicDataStructure; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class EnvelopeData - The digital envelope data object. |
|
13
|
|
|
* |
|
14
|
|
|
* @package CryptoManana\DataStructures |
|
15
|
|
|
* |
|
16
|
|
|
* @property string $key The encrypted secret key. |
|
17
|
|
|
* @property string $iv The encrypted initialization vector. |
|
18
|
|
|
* @property string $cipherData The encrypted message information. |
|
19
|
|
|
* @property string $authenticationTag The message authentication code (tag). |
|
20
|
|
|
*/ |
|
21
|
|
|
class EnvelopeData extends BasicDataStructure |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* The concealed symmetric encryption secret key property storage. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string The encrypted secret key. |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $key = ''; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The concealed symmetric encryption initialization vector property storage. |
|
32
|
|
|
* |
|
33
|
|
|
* @var string The encrypted initialization vector. |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $iv = ''; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The encrypted information property storage. |
|
39
|
|
|
* |
|
40
|
|
|
* @var string The encrypted data information. |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $cipherData = ''; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* The message authentication code property storage. |
|
46
|
|
|
* |
|
47
|
|
|
* @var string The message authentication code (tag). |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $authenticationTag = ''; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Envelope constructor. |
|
53
|
|
|
* |
|
54
|
|
|
* @param string $encryptedKey The encrypted secret key. |
|
55
|
|
|
* @param string $encryptedIv The encrypted initialization vector. |
|
56
|
|
|
* @param string $encryptedData The encrypted message data information. |
|
57
|
|
|
* @param string $digestionTag The message authentication code (tag). |
|
58
|
|
|
*/ |
|
59
|
|
|
public function __construct($encryptedKey = '', $encryptedIv = '', $encryptedData = '', $digestionTag = '') |
|
60
|
|
|
{ |
|
61
|
|
|
if (is_string($encryptedKey)) { |
|
|
|
|
|
|
62
|
|
|
$this->key = $encryptedKey; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if (is_string($encryptedIv)) { |
|
|
|
|
|
|
66
|
|
|
$this->iv = $encryptedIv; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if (is_string($encryptedData)) { |
|
|
|
|
|
|
70
|
|
|
$this->cipherData = $encryptedData; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
if (is_string($digestionTag)) { |
|
|
|
|
|
|
74
|
|
|
$this->authenticationTag = $digestionTag; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Envelope destructor |
|
80
|
|
|
*/ |
|
81
|
|
|
public function __destruct() |
|
82
|
|
|
{ |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* The envelope string representation. |
|
87
|
|
|
* |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function __toString() |
|
91
|
|
|
{ |
|
92
|
|
|
return 'key : ' . $this->key . |
|
93
|
|
|
' | iv : ' . $this->iv . |
|
94
|
|
|
' | encrypted : ' . $this->cipherData . |
|
95
|
|
|
' | tag : ' . $this->authenticationTag; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|