项目作者: fukamachi

项目描述 :
A JOSE implementation
高级语言: Common Lisp
项目地址: git://github.com/fukamachi/jose.git
创建时间: 2017-06-19T03:20:42Z
项目社区:https://github.com/fukamachi/jose

开源协议:

下载


jose

Quicklisp dist
Build Status
Coverage Status

A JSON Object Signing and Encryption (JOSE) implementation for Common Lisp.

Usage

HMAC

  1. (defvar *key* (ironclad:ascii-string-to-byte-array "my$ecret"))
  2. (defvar *token*
  3. (jose:encode :hs256 *key* '(("hello" . "world"))))
  4. *token*
  5. ;=> "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJoZWxsbyI6IndvcmxkIn0.Vr0VKL9WHX9lUPWzrE0DX4fEvl0_CgnKlzI2mWiro8E"
  6. (jose:decode :hs256 *key* *token*)
  7. ;=> (("hello" . "world"))
  8. ; (("alg" . "HS256") ("typ" . "JWT"))
  9. ;; Decoding without signature verification.
  10. (jose:inspect-token *token*)
  11. ;=> (("hello" . "world"))
  12. ; (("alg" . "HS256") ("typ" . "JWT"))
  13. ; #(142 123 175 222 84 4 134 19 70 182 50 209 29 113 176 40 82 42 241 90 230 91
  14. ; 176 235 254 57 221 93 97 220 6 101)

RSA

For RSA algorithm, the key must be an instance of Ironclad public/private key, that can be generated with ironclad:generate-key-pair.

To read from OpenSSH key files, use cl-ssh-keys. To parse ASN.1 keys, asn1 library will help.

  1. ;; Generate a new key pairs with Ironclad
  2. (defvar *private-key*
  3. (ironclad:generate-key-pair :rsa :num-bits 2048))
  4. ;; Or, read a private key file generated by OpenSSH
  5. (defvar *private-key*
  6. (ssh-keys:parse-private-key-file #P"~/.ssh/id_rsa"))
  7. (defvar *token*
  8. (jose:encode :rs256 *private-key* '(("hello" . "world"))))

Supported Algorithms

  • HS256
  • HS384
  • HS512
  • RS256
  • RS384
  • RS512
  • PS256
  • PS384
  • PS512
  • none

See Also

Author

Copyright (c) 2017 Eitaro Fukamachi (e.arrows@gmail.com)

License

Licensed under the BSD 2-Clause License.