@@ -45,29 +45,19 @@ public function __construct(
45
45
) {
46
46
$ this ->cipher = $ cipher ;
47
47
$ this ->mode = $ mode ;
48
- // @codingStandardsIgnoreStart
48
+ // @codingStandardIgnoreLine
49
49
$ this ->handle = @mcrypt_module_open ($ cipher , '' , $ mode , '' );
50
- // @codingStandardsIgnoreEnd
51
50
try {
52
- // @codingStandardsIgnoreStart
51
+ // @codingStandardIgnoreLine
53
52
$ maxKeySize = @mcrypt_enc_get_key_size ($ this ->handle );
54
- // @codingStandardsIgnoreEnd
55
53
if (strlen ($ key ) > $ maxKeySize ) {
56
54
throw new \Magento \Framework \Exception \LocalizedException (
57
55
new \Magento \Framework \Phrase ('Key must not exceed %1 bytes. ' , [$ maxKeySize ])
58
56
);
59
57
}
60
- // @codingStandardsIgnoreStart
58
+ // @codingStandardIgnoreLine
61
59
$ initVectorSize = @mcrypt_enc_get_iv_size ($ this ->handle );
62
- // @codingStandardsIgnoreEnd
63
- if (true === $ initVector ) {
64
- /* Generate a random vector from human-readable characters */
65
- $ abc = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ' ;
66
- $ initVector = '' ;
67
- for ($ i = 0 ; $ i < $ initVectorSize ; $ i ++) {
68
- $ initVector .= $ abc [rand (0 , strlen ($ abc ) - 1 )];
69
- }
70
- } elseif (false === $ initVector ) {
60
+ if (null === $ initVector ) {
71
61
/* Set vector to zero bytes to not use it */
72
62
$ initVector = str_repeat ("\0" , $ initVectorSize );
73
63
} elseif (!is_string ($ initVector ) || strlen ($ initVector ) != $ initVectorSize ) {
@@ -80,14 +70,12 @@ public function __construct(
80
70
}
81
71
$ this ->_initVector = $ initVector ;
82
72
} catch (\Exception $ e ) {
83
- // @codingStandardsIgnoreStart
73
+ // @codingStandardIgnoreLine
84
74
@mcrypt_module_close ($ this ->handle );
85
- // @codingStandardsIgnoreEnd
86
- throw $ e ;
75
+ throw new \Magento \Framework \Exception \LocalizedException (new \Magento \Framework \Phrase ($ e ->getMessage ()));
87
76
}
88
- // @codingStandardsIgnoreStart
77
+ // @codingStandardIgnoreLine
89
78
@mcrypt_generic_init ($ this ->handle , $ key , $ initVector );
90
- // @codingStandardsIgnoreEnd
91
79
}
92
80
93
81
/**
@@ -97,8 +85,6 @@ public function __destruct()
97
85
{
98
86
// @codingStandardsIgnoreStart
99
87
@mcrypt_generic_deinit ($ this ->handle );
100
- // @codingStandardsIgnoreEnd
101
- // @codingStandardsIgnoreStart
102
88
@mcrypt_module_close ($ this ->handle );
103
89
// @codingStandardsIgnoreEnd
104
90
}
@@ -158,9 +144,8 @@ public function decrypt(string $data): string
158
144
if (strlen ($ data ) == 0 ) {
159
145
return $ data ;
160
146
}
161
- // @codingStandardsIgnoreStart
147
+ // @codingStandardIgnoreLine
162
148
$ data = @mdecrypt_generic ($ this ->handle , $ data );
163
- // @codingStandardsIgnoreEnd
164
149
/*
165
150
* Returned string can in fact be longer than the unencrypted string due to the padding of the data
166
151
* @link http://www.php.net/manual/en/function.mdecrypt-generic.php
0 commit comments