https://github.com/r-lib/jose
Javascript Object Signing and Encryption for R
https://github.com/r-lib/jose
Last synced: 5 months ago
JSON representation
Javascript Object Signing and Encryption for R
- Host: GitHub
- URL: https://github.com/r-lib/jose
- Owner: r-lib
- License: other
- Created: 2016-02-10T21:40:31.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2024-09-09T17:50:42.000Z (7 months ago)
- Last Synced: 2024-09-09T21:58:22.388Z (7 months ago)
- Language: R
- Size: 92.8 KB
- Stars: 50
- Watchers: 4
- Forks: 9
- Open Issues: 6
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - r-lib/jose - Javascript Object Signing and Encryption for R (R)
README
# jose
[](https://app.travis-ci.com/jeroen/jose)
[](https://ci.appveyor.com/project/jeroen/jose)
[](https://app.codecov.io/github/jeroen/jose?branch=master)
[](http://cran.r-project.org/package=jose)
[](http://cran.r-project.org/web/packages/jose/index.html)> JavaScript Object Signing and Encryption
Read and write JSON Web Keys (JWK, rfc7517), generate and verify JSON
Web Signatures (JWS, rfc7515) and encode/decode JSON Web Tokens (JWT, rfc7519).
These standards provide modern signing and encryption formats that are natively
supported by browsers via the JavaScript WebCryptoAPI, and used by services
like OAuth 2.0, LetsEncrypt, and Github Apps.## Documentation
Vignettes for the R package:
- [Reading/Writing JSON Web Keys (JWK) in R](https://cran.r-project.org/web/packages/jose/vignettes/jwk.html)
- [Encoding/Decoding JSON Web Tokens (JWT) in R](https://cran.r-project.org/web/packages/jose/vignettes/jwt.html)Specifications and standards:
- JOSE RFC Tracker: https://datatracker.ietf.org/wg/jose/documents/
- Browser WebCryptoAPI API: https://www.w3.org/TR/WebCryptoAPI/#jose
- ACME Protocol (LetsEncrypt): https://ietf-wg-acme.github.io/acme/draft-ietf-acme-acme.html## JSON Web Keys (JWK)
```r
library(jose)# generate an ecdsa key
key <- ec_keygen("P-521")
write_jwk(key)
write_jwk(as.list(key)$pubkey)# Same for RSA
key <- rsa_keygen()
write_jwk(key)
write_jwk(as.list(key)$pubkey)
```## JSON Web Tokens (JWT)
```r
# HMAC signing
mysecret <- "This is super secret"
token <- jwt_claim(name = "jeroen", session = 123456)
sig <- jwt_encode_hmac(token, mysecret)
jwt_decode_hmac(sig, mysecret)# RSA encoding
mykey <- openssl::rsa_keygen()
pubkey <- as.list(mykey)$pubkey
sig <- jwt_encode_sig(token, mykey)
jwt_decode_sig(sig, pubkey)# Same with EC
mykey <- openssl::ec_keygen()
pubkey <- as.list(mykey)$pubkey
sig <- jwt_encode_sig(token, mykey)
jwt_decode_sig(sig, pubkey)
```