@@ -38,11 +38,13 @@ class JWT
38
38
/**
39
39
* Decodes a JWT string into a PHP object.
40
40
*
41
- * @param string $jwt The JWT
42
- * @param string|Array|null $key The secret key, or map of keys
43
- * @param Array $allowed_algs List of supported verification algorithms
41
+ * @param string $jwt The JWT
42
+ * @param string|array|null $key The key, or map of keys.
43
+ * If the algorithm used is asymmetric, this is the public key
44
+ * @param array $allowed_algs List of supported verification algorithms
45
+ * Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
44
46
*
45
- * @return object The JWT's payload as a PHP object
47
+ * @return object The JWT's payload as a PHP object
46
48
*
47
49
* @throws DomainException Algorithm was not provided
48
50
* @throws UnexpectedValueException Provided JWT was invalid
@@ -120,13 +122,15 @@ public static function decode($jwt, $key = null, $allowed_algs = array())
120
122
/**
121
123
* Converts and signs a PHP object or array into a JWT string.
122
124
*
123
- * @param object|array $payload PHP object or array
124
- * @param string $key The secret key
125
- * @param string $alg The signing algorithm. Supported
126
- * algorithms are 'HS256', 'HS384' and 'HS512'
127
- * @param array $head An array with header elements to attach
125
+ * @param object|array $payload PHP object or array
126
+ * @param string $key The secret key.
127
+ * If the algorithm used is asymmetric, this is the private key
128
+ * @param string $alg The signing algorithm.
129
+ * Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
130
+ * @param array $head An array with header elements to attach
131
+ *
132
+ * @return string A signed JWT
128
133
*
129
- * @return string A signed JWT
130
134
* @uses jsonEncode
131
135
* @uses urlsafeB64Encode
132
136
*/
@@ -153,12 +157,13 @@ public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $he
153
157
/**
154
158
* Sign a string with a given key and algorithm.
155
159
*
156
- * @param string $msg The message to sign
157
- * @param string|resource $key The secret key
158
- * @param string $alg The signing algorithm. Supported algorithms
159
- * are 'HS256', 'HS384', 'HS512' and 'RS256'
160
+ * @param string $msg The message to sign
161
+ * @param string|resource $key The secret key
162
+ * @param string $alg The signing algorithm.
163
+ * Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256'
164
+ *
165
+ * @return string An encrypted message
160
166
*
161
- * @return string An encrypted message
162
167
* @throws DomainException Unsupported algorithm was specified
163
168
*/
164
169
public static function sign ($ msg , $ key , $ alg = 'HS256 ' )
@@ -182,13 +187,16 @@ public static function sign($msg, $key, $alg = 'HS256')
182
187
}
183
188
184
189
/**
185
- * Verify a signature with the mesage , key and method. Not all methods
190
+ * Verify a signature with the message , key and method. Not all methods
186
191
* are symmetric, so we must have a separate verify and sign method.
187
- * @param string $msg the original message
188
- * @param string $signature
189
- * @param string|resource $key for HS*, a string key works. for RS*, must be a resource of an openssl public key
190
- * @param string $alg
192
+ *
193
+ * @param string $msg The original message (header and body)
194
+ * @param string $signature The original signature
195
+ * @param string|resource $key For HS*, a string key works. for RS*, must be a resource of an openssl public key
196
+ * @param string $alg The algorithm
197
+ *
191
198
* @return bool
199
+ *
192
200
* @throws DomainException Invalid Algorithm or OpenSSL failure
193
201
*/
194
202
private static function verify ($ msg , $ signature , $ key , $ alg )
@@ -229,7 +237,8 @@ private static function verify($msg, $signature, $key, $alg)
229
237
*
230
238
* @param string $input JSON string
231
239
*
232
- * @return object Object representation of JSON string
240
+ * @return object Object representation of JSON string
241
+ *
233
242
* @throws DomainException Provided string was invalid JSON
234
243
*/
235
244
public static function jsonDecode ($ input )
@@ -263,7 +272,8 @@ public static function jsonDecode($input)
263
272
*
264
273
* @param object|array $input A PHP object or array
265
274
*
266
- * @return string JSON representation of the PHP object or array
275
+ * @return string JSON representation of the PHP object or array
276
+ *
267
277
* @throws DomainException Provided object could not be encoded to valid JSON
268
278
*/
269
279
public static function jsonEncode ($ input )
@@ -331,6 +341,7 @@ private static function handleJsonError($errno)
331
341
* Get the number of bytes in cryptographic strings.
332
342
*
333
343
* @param string
344
+ *
334
345
* @return int
335
346
*/
336
347
private static function safeStrlen ($ str )
0 commit comments