1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace Sop\PKCS5\ASN1\AlgorithmIdentifier; |
6
|
|
|
|
7
|
|
|
use Sop\ASN1\Type\Constructed\Sequence; |
8
|
|
|
use Sop\CryptoTypes\AlgorithmIdentifier\AlgorithmIdentifier; |
9
|
|
|
use Sop\CryptoTypes\AlgorithmIdentifier\AlgorithmIdentifierFactory; |
10
|
|
|
use Sop\CryptoTypes\AlgorithmIdentifier\Feature\EncryptionAlgorithmIdentifier; |
11
|
|
|
use Sop\CryptoTypes\AlgorithmIdentifier\SpecificAlgorithmIdentifier; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Base class for Password-Based Cryptography schemes. |
15
|
|
|
* |
16
|
|
|
* @see https://tools.ietf.org/html/rfc2898 |
17
|
|
|
*/ |
18
|
|
|
abstract class PBEAlgorithmIdentifier extends SpecificAlgorithmIdentifier implements EncryptionAlgorithmIdentifier |
19
|
|
|
{ |
20
|
|
|
const OID_PBE_WITH_MD2_AND_DES_CBC = '1.2.840.113549.1.5.1'; |
21
|
|
|
const OID_PBE_WITH_MD5_AND_DES_CBC = '1.2.840.113549.1.5.3'; |
22
|
|
|
const OID_PBE_WITH_MD2_AND_RC2_CBC = '1.2.840.113549.1.5.4'; |
23
|
|
|
const OID_PBE_WITH_MD5_AND_RC2_CBC = '1.2.840.113549.1.5.6'; |
24
|
|
|
const OID_PBE_WITH_MD5_AND_XOR = '1.2.840.113549.1.5.9'; |
25
|
|
|
const OID_PBE_WITH_SHA1_AND_DES_CBC = '1.2.840.113549.1.5.10'; |
26
|
|
|
const OID_PBE_WITH_SHA1_AND_RC2_CBC = '1.2.840.113549.1.5.11'; |
27
|
|
|
const OID_PBES2 = '1.2.840.113549.1.5.13'; |
28
|
|
|
const OID_PBMAC1 = '1.2.840.113549.1.5.14'; |
29
|
|
|
|
30
|
|
|
// PKCS #12 algorithms |
31
|
|
|
const OID_PBE_WITH_SHA1_AND_RC4_128 = '1.2.840.113549.1.12.1.1'; |
32
|
|
|
const OID_PBE_WITH_SHA1_AND_RC4_40 = '1.2.840.113549.1.12.1.2'; |
33
|
|
|
const OID_PBE_WITH_SHA1_AND_3KEY_3DES_CBC = '1.2.840.113549.1.12.1.3'; |
34
|
|
|
const OID_PBE_WITH_SHA1_AND_2KEY_3DES_CBC = '1.2.840.113549.1.12.1.4'; |
35
|
|
|
const OID_PBE_WITH_SHA1_AND_RC2_128_CBC = '1.2.840.113549.1.12.1.5'; |
36
|
|
|
const OID_PBE_WITH_SHA1_AND_RC2_40_CBC = '1.2.840.113549.1.12.1.6'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Salt. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $_salt; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Iteration count. |
47
|
|
|
* |
48
|
|
|
* @var int |
49
|
|
|
*/ |
50
|
|
|
protected $_iterationCount; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Constructor. |
54
|
|
|
* |
55
|
|
|
* @param string $salt |
56
|
|
|
* @param int $iteration_count |
57
|
|
|
*/ |
58
|
21 |
|
public function __construct(string $salt, int $iteration_count) |
59
|
|
|
{ |
60
|
21 |
|
$this->_salt = $salt; |
61
|
21 |
|
$this->_iterationCount = $iteration_count; |
62
|
21 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param Sequence $seq |
66
|
|
|
* |
67
|
|
|
* @return AlgorithmIdentifier |
68
|
|
|
*/ |
69
|
13 |
|
public static function fromASN1(Sequence $seq): AlgorithmIdentifier |
70
|
|
|
{ |
71
|
13 |
|
return (new AlgorithmIdentifierFactory( |
72
|
13 |
|
new PKCS5AlgorithmIdentifierProvider()))->parse($seq); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get salt. |
77
|
|
|
* |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
24 |
|
public function salt(): string |
81
|
|
|
{ |
82
|
24 |
|
return $this->_salt; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get iteration count. |
87
|
|
|
* |
88
|
|
|
* @return int |
89
|
|
|
*/ |
90
|
24 |
|
public function iterationCount(): int |
91
|
|
|
{ |
92
|
24 |
|
return $this->_iterationCount; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|