Download the PHP package itaiarbel/jwt without Composer
On this page you can find all versions of the php package itaiarbel/jwt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download itaiarbel/jwt
More information about itaiarbel/jwt
Files in itaiarbel/jwt
Informations about the package jwt
PHP Jwt library by Itai Arbel
Easy to use lightweight user friendly jwt library no dependencies - all algorithms implemented using php openssl only.
Disclaimer:
22/08/2020 - BETA - all seems to be working ok,
NOT fully tested for security / NOT fully RFC complience. use at your own risk!
You are wellcome to use this library and help me improve it by finding bugs and implementing missing algorithms.
What it can do?
- JWS - HS256 - Sign / Verify - with shared secret key
- JWS - HS384 - Sign / Verify - with shared secret key
- JWS - HS512 - Sign / Verify - with shared secret key
- JWS - RS256 - Sign / Verify - with private & private key
- JWS - RS384 - Sign / Verify - with private & private key
- JWS - RS512 - Sign / Verify - with private & private key
- JWE - RSA1_5 + A128CBC-HS256 - Encrypt / Decrypt - with private & private key
- JWE - RSA1_5 + A192CBC-HS384 - Encrypt / Decrypt - with private & private key
- JWE - RSA1_5 + A256CBC-HS512 - Encrypt / Decrypt - with private & private key
- JWE - RSA1_5 + A128GCM - Encrypt / Decrypt - with private & private key
- JWE - RSA1_5 + A192GCM - Encrypt / Decrypt - with private & private key
- JWE - RSA1_5 + A256GCM - Encrypt / Decrypt - with private & private key
Table of Contents
-
Installetion
- Builder
-
Builder Methods
- Checker
-
Checker Methods
-
Algorithms
- Contributions
- Contact
Installation
Run the following composer command:
Then use it in your project:
Builder
allows you to build jwt, then sign/encrypt them.
Example of use:
Builder Methods
claim(key, val) / claims([key=>val,key=>val...]) : addes a claim/claims to the payload section of the token
header(key, val) : addes a claim to the header section of the token (notice: header claims are not ecnrypted in JWE)
exp(secs,server_ts[opt]) : adds 'exp' token expiers time claim of time()+secs, you can set server timestamp if different timezone.
nfb(secs) : adds a 'nbf' token not valid before claim of time()+secs
jti(val[opt]) : adds a 'jti' token id claim of auto generated random GUID if no parameter provided
iss(val)/issuer(val) : adds a 'iss' token issuer claim
sign(key, alg) : finish the builder and sign the jwt. - > JWS
encrypt(key, alg, enc) : finish the builder and encrypt the jwt. -> JWE
Checker
Example of use:
JWS verify:
JWE decryption:
Note: verified Not means Valid token, i'ts only checks signiture, not validity of the token time, you must check the experation timestamp/nbf/iss blacklist/catch/database ect on your own...
Checker Methods
verify(key/secret,alg) - verify JWS using public key / secret
decrypt(key/secret,alg,enc) - decrypting JWE using public key
getHeaderClaims():array - get array of all header claims in JWE/JWS
getHeaderClaim(name):string - get a specific claim from header
hasHeaderClaim(name):bool - returns true/false if header claim exist
kid()/keyId():string - get 'kid' calim from header
alg()/algorithm():string - get 'alg' calim from header
enc()/encryption():string - get 'enc' calim from header
validate(server_ts[opt]):bool - validates signiture/decryption + exp + nbf
checkExp(ts[opt]):bool - return true/false if exp claim time has passed
checkNbf(ts[opt]):bool - return true/false if nbf time not before now.. note: if nbf claim not exist - returns true this this claim is optional
checkClaim(name,expected_val):bool - return true/false - check claim agains expected value
checkHeaderClaim(name,expected_val):bool - return true/false - check header claim agains expected value
getClaims():array - get array of all claims (will return empy array if token yet to be decrypted)
getClaim(name):string - get specific claim by name (will return empty string if token yet to be decrypted)
hasClaim(name):bool - returns true/false if claim exist (will return false if token yet to be decrypted)
iss()/issuer():string - get isueer 'iss' claim
sub()/subject():string - get subject 'sub' claim
aud()/audience():string - get audience 'aud' claim
exp()/expires():string - get expires time 'exp' claim
nbf()/notBefore():string - get not before time 'nbf' claim
iat()/issuedAt():string - get issued time 'iat' claim
jti()/id():string - - get token id 'jti' claim
Algorithms
Algorithms Implemented:
- HS256 - HMAC-SHA256 - Sign / Verify
- HS384 - HMAC-SHA384 - Sign / Verify
- HS512 - HMAC-SHA512 - Sign / Verify
- RS256 - RSA-PKCS1-SHA256 - Sign / Verify
- RS384 - RSA-PKCS1-SHA384 - Sign / Verify
- RS512 - RSA-PKCS1-SHA512 - Sign / Verify
- RSA1_5 - Encrypt Key / Decrypt Key
- A128CBC_HS256 - AES-128-CBC SHA256 - Encrypt / Decrypt
- A192CBC_HS384 - AES-192-CBC SHA384 - Encrypt / Decrypt
- A256CBC_HS512 - AES-256-CBC SHA512 - Encrypt / Decrypt
- A128GCM - AES-128-GCM - Encrypt / Decrypt
- A192GCM - AES-192-GCM - Encrypt / Decrypt
- A256GCM - AES-256-GCM - Encrypt / Decrypt
Algorithms TODO: (maybe you can help?)
- dir
- PS256
- PS384
- PS512
- ES256
- ES384
- ES512
- RSA-OAEP
- RSA-OAEP-256
- A128KW
- A192KW
- A256KW
- ECDH-ES
- ECDH-ES+A128KW
- ECDH-ES+A192KW
- ECDH-ES+A256KW
- A128GCMKW
- A192GCMKW
- A256GCMKW
- PBES2-HS256+A128KW
- PBES2-HS384+A192KW
- PBES2-HS512+A256KW
Contributions
ways to contribute:
- add algorithms
- find bugs
- fix bugs
- improve existing code
Support
- buy me a cup of coffee
Contact
You can contact me at [email protected]