From 73a72f19fc62e62ea24715a16355894f0ff27ade Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Tue, 15 Sep 2020 11:53:52 +0000 Subject: [PATCH] jwt : add the cipher algorithm in parameter git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@6117 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- jwt.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/jwt.php b/jwt.php index 6b9f784..c59d294 100644 --- a/jwt.php +++ b/jwt.php @@ -35,11 +35,13 @@ class jwt * @param string|null $alg The algorithm to use to sign the token (default * is HS256) * Allowed algorithms : HS256, HS512, HS384 - * @param string|null $ckey The cipher key to encrypt the payload (24 chars - * length) + * @param string|null $ckey The cipher key to encrypt the payload + * @param string|null $cipherMethod The method to cipher the payload + * des-ede3-cbc by default * @return string The Token */ - public function encode ($payload, $key, $alg = "HS256", $ckey = null) + public function encode ($payload, $key, $alg = "HS256", $ckey = null, + $cipherMethod = "des-ede3-cbc") // {{{ { if (! key_exists ($alg, $this->supportedAlgs)) @@ -52,7 +54,7 @@ class jwt if ($ckey) { $encrypt = new encrypt (); - $payload = $encrypt->encrypt ($payload, $ckey); + $payload = $encrypt->encrypt ($payload, $ckey, $cipherMethod); } $segments[] = $this->urlsafeB64Encode ($payload); $toBeSigned = implode ('.', $segments); @@ -67,13 +69,15 @@ class jwt * @param string $key The key used to sign the message * @param array|null $allowedAlg List of allowed algorithms. If null, all the * algorithms defined in $this->supportedAlgs are allowed - * @param string|null $ckey The cipher key to decrypt the payload (24 chars - * length) + * @param string|null $ckey The cipher key to decrypt the payload + * @param string|null $cipherMethod The method to cipher the payload + * des-ede3-cbc by default * @return array the decoded payload * @throw Exception if the key is not able to verify the token with the * provided password */ - public function decode ($jwt, $key, $allowedAlg = null, $ckey = null) + public function decode ($jwt, $key, $allowedAlg = null, $ckey = null, + $cipherMethod = "des-ede3-cbc") // {{{ { if ($allowedAlg === null)