• This repository has been archived on 03/Jan/2024
  • Stars
    star
    138
  • Rank 264,508 (Top 6 %)
  • Language
    PHP
  • License
    Other
  • Created over 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PHP JOSE Library (JWT, JWS, JWE, JWK, JWK Set, JWK Thumbprint are supported)

JOSE

PHP JOSE (Javascript Object Signing and Encryption) Implementation

Build Status

Requirements

phpseclib is required. http://phpseclib.sourceforge.net

Example

JWT

Encoding

$jwt = new JOSE_JWT(array(
    'foo' => 'bar'
));
$jwt->toString();

Decoding

$jwt_string = 'eyJ...';
$jwt = JOSE_JWT::decode($jwt_string);

JWS

Signing

$private_key = "-----BEGIN RSA PRIVATE KEY-----\n....";
$jwt = new JOSE_JWT(array(
    'foo' => 'bar'
));
$jws = $jwt->sign($private_key, 'RS256');

NOTE: $private_key can be phpseclib\Crypt\RSA instance.

Verification

$public_key = "-----BEGIN RSA PUBLIC KEY-----\n....";
$jwt_string = 'eyJ...';
$jws = JOSE_JWT::decode($jwt_string);
$jws->verify($public_key, 'RS256');

NOTE: $public_key can be JOSE_JWK or phpseclib\Crypt\RSA instance.

JWE

Encryption

$jwe = new JOSE_JWE($plain_text);
$jwe->encrypt(file_get_contents('/path/to/public_key.pem'));
$jwe->toString();

Decryption

$jwt_string = 'eyJ...';
$jwe = JOSE_JWT::decode($jwt_string);
$jwe->decrypt($private_key);

JWK

Encode

RSA Public Key
$public_key = new phpseclib\Crypt\RSA();
$public_key->loadKey('-----BEGIN RSA PUBLIC KEY-----\n...');
JOSE_JWK::encode($public_key); # => JOSE_JWK instance
RSA Private Key
$private_key = new phpseclib\Crypt\RSA();
$private_key->setPassword($pass_phrase); # skip if not encrypted
$private_key->loadKey('-----BEGIN RSA PRIVATE KEY-----\n...');
JOSE_JWK::encode($private_key); # => JOSE_JWK instance

Decode

RSA Public Key
# public key
$components = array(
    'kty' => 'RSA',
    'e' => 'AQAB',
    'n' => 'x9vNhcvSrxjsegZAAo4OEuo...'
);
JOSE_JWK::decode($components); # => phpseclib\Crypt\RSA instance
RSA Private Key

Not supported.

Run Test

git clone git://github.com/nov/jose-php.git
cd jose
php composer.phar install --dev
./vendor/bin/phpunit -c test/phpunit.xml --tap

Copyright

Copyright Β© 2013 Nov Matake & GREE Inc. See LICENSE for details.

More Repositories

1

fb_graph

This gem doesn't support FB Graph API v2.0+. Please use fb_graph2 gem instead.
Ruby
1,035
star
2

rack-oauth2

OAuth 2.0 Server & Client Library. Both Bearer and MAC token type are supported.
Ruby
691
star
3

openid_connect

OpenID Connect Server & Client Library
Ruby
405
star
4

paypal-express

Ruby Gem for PayPal Express Checkout API
Ruby
372
star
5

json-jwt

JSON Web Token and its family (JSON Web Signature, JSON Web Encryption and JSON Web Key) in Ruby
Ruby
296
star
6

apple_id

Sign in with Apple backend library in Ruby
Ruby
198
star
7

fb_graph2

Ruby
107
star
8

fb_graph_sample

An rails app using fb_graph. Learn how to authenticate facebook users using fb_graph and facebook's JavaScript SDK or OAuth2.
Ruby
105
star
9

itunes-receipt

Handle iTunes In App Purchase Receipt Verification
Ruby
94
star
10

paypal-express-sample

Learn how to use PayPal Express API in your Rails app.
Ruby
54
star
11

openid_connect_sample

Ruby
46
star
12

rack-oauth2-sample

Rack::OAuth2 Sample Server (Bearer)
Ruby
44
star
13

openid_connect_sample_rp

Ruby
25
star
14

activitystreams

RubyGem for ActivityStreams Publishers
Ruby
20
star
15

square

Square API Client
Ruby
19
star
16

web_authn

W3C Web Authentication API (a.k.a. WebAuthN / FIDO 2.0) RP library in Ruby
Ruby
19
star
17

signin-with-apple

Sample app for β€œapple_id” ruby gem.
Ruby
17
star
18

motion-oauth2

Ruby
16
star
19

webfinger

WebFinger Client in Ruby
Ruby
15
star
20

twitter_oauth2

Twitter OAuth 2.0 Client Library in Ruby
Ruby
13
star
21

oauth_sample

OAuth sample consumer & provider
Ruby
13
star
22

attr_required

Provide attr_required with presence validation
Ruby
9
star
23

fb_graph-mock

Ruby
9
star
24

openid_connect_sample2

Ruby
8
star
25

jsonbuilder

Json builder which has the same interface with Builder::XmlMarkup
Ruby
7
star
26

rack-oauth2-sample-mac

Rack::OAuth2 Sample Server (MAC)
Ruby
7
star
27

web_authn_sample

Ruby
5
star
28

rack-locale_memorable

Ruby
4
star
29

iknow

moved to smartfm
4
star
30

SWD

SWD (Simple Web Discovery) Client Library
Ruby
4
star
31

connect

Yet Another OpenID Connect Gem... might be
Ruby
3
star
32

connect-rp-certified

Ruby
3
star
33

apple_pay

Ruby
3
star
34

cose-key

COSE Key (RSA & EC) in Ruby
Ruby
3
star
35

rubymotion-crypto-sample

Ruby
3
star
36

FB-Connect

Objective-C
3
star
37

safie

Safie API Client in Ruby
Ruby
2
star
38

CookieFlash

Cookie-based Rails flash
JavaScript
2
star
39

nov.github.io

GitHub Pages Repository
HTML
2
star
40

CredentialsAPI

Java
2
star
41

gadgets

OpenSocial Gadgets
JavaScript
2
star
42

draft-ietf-oauth

OAuth 2.0
2
star
43

oauth.jp-karma

OAuth.jp Karma
Ruby
2
star
44

AccountManager

Java
2
star
45

alb-backed

Ruby
1
star
46

tower-sample

CoffeeScript
1
star
47

cocoa_teks

Ruby
1
star
48

oauth.jp

SCSS
1
star
49

faraday-jwt

Ruby
1
star
50

oauth-wmrm-sample

HTML
1
star
51

openid_sample

Sample OpenID Relying Party (with AX & UI Extension)
Ruby
1
star
52

apple-pay-js

1
star
53

restclient_with_cert

RestClient with embedded cert
Ruby
1
star
54

persona

JavaScript
1
star
55

SecureRandom

SecureRandom in PHP
PHP
1
star
56

otp-sample

Rails Sample for Google Authenticator
Ruby
1
star
57

iOS-Enterprise-SSO

iOS Enterprise SSO Test App
Swift
1
star
58

idcon

CSS
1
star
59

account-chooser

Account Chooser RP Sample
Ruby
1
star
60

try_git

1
star
61

crash-on-ios6

Ruby
1
star
62

backplane-sample

Ruby
1
star
63

connectable

Rails sample for connectable protocols
Ruby
1
star