3 homepage: https://github.com/therootcompany/keypairs
5 keypairs: a cross-platform tool for RSA, ECDSA, JWT, JOSE, and general asymmetric encryption
8 To update or switch versions, run `webi keypairs@stable`.
12 > keypairs is like JWT.io, at your fingertips.
14 - Generates NIST standard RSA and ECDSA keys
15 - Signatures output as JWT and JWS (JSONE)
18 ### How to generate JSON Web Keys (JWKs)
21 # keypairs gen -key <key.format> -pub <pub.format>
22 keypairs gen -key key.jwk.json -pub pub.jwk.json
25 JWK is the default format, for which you can use stdout (key) and stderr (pub)
28 keypairs gen > key.jwk.json 2> pub.jwk.json
31 ### How to generate PEM (PKCS) keys
34 keypairs gen -key key.pem -pub pub.pem
40 keypairs gen -key key.der -pub pub.der
43 ### How to sign a payload
46 # keypairs sign --exp 1h <priv key> <data or file> > token.jwt 2> sig.jws
47 keypairs sign --exp 1h key.jwk.json '{ "sub": "me@example.com" }' > token.jwt 2> sig.jws
50 A JWT (JSON Web Token) has 3 sections (protected header, payload, and signature)
51 separated by dots (`.`):
54 eyJhbGciOiJFUzI1NiIsImtpZCI6ImpkeHhZY1NCZUJfeUdoZWlCVW14NjF0eHExZGFjR1hIX191bEJuWlZHMEUiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjIxNDczODU3MTIsInN1YiI6Im1lQGV4YW1wbGUuY29tIn0.oh8-PUMdrbQU6seRXjo68wPWAKbA-V9LMnd_wZEkPHc3C8A5xJzV7mDDMNOLEy4VcuNGxced_yjYulzcMa5FLQ
57 A JWS (JSON Web Signature), is just a parsed JWT:
63 "sub": "me@example.com"
67 "kid": "jdxxYcSBeB_yGheiBUmx61txq1dacGXH__ulBnZVG0E",
70 "payload": "eyJleHAiOjIxNDczODU3MTIsInN1YiI6Im1lQGV4YW1wbGUuY29tIn0",
71 "protected": "eyJhbGciOiJFUzI1NiIsImtpZCI6ImpkeHhZY1NCZUJfeUdoZWlCVW14NjF0eHExZGFjR1hIX191bEJuWlZHMEUiLCJ0eXAiOiJKV1QifQ",
72 "signature": "oh8-PUMdrbQU6seRXjo68wPWAKbA-V9LMnd_wZEkPHc3C8A5xJzV7mDDMNOLEy4VcuNGxced_yjYulzcMa5FLQ"
76 Note that self-signed JWTs and JWSes will use `jwk` as the full public key
77 rather than the `kid` thumbprint.
79 ### How to verify a signature
82 # keypairs verify <pub key> <signed file or data>
83 keypairs verify pub.jwk.json token.jwt
86 You can use files or strings.
90 '{ "crv": "P-256", "kty": "EC", "x": "5K5ALgtWw37KsZOrBdwCyGOGKCFd27u-t61dmUiieJY", "y": "wr3BNL-CeqkGtiRVqo3yizKxUA0bwS1MNZeqytdwICA" }' \
91 eyJhbGciOiJFUzI1NiIsImtpZCI6ImpkeHhZY1NCZUJfeUdoZWlCVW14NjF0eHExZGFjR1hIX191bEJuWlZHMEUiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjIxNDczODU3MTIsInN1YiI6Im1lQGV4YW1wbGUuY29tIn0.oh8-PUMdrbQU6seRXjo68wPWAKbA-V9LMnd_wZEkPHc3C8A5xJzV7mDDMNOLEy4VcuNGxced_yjYulzcMa5FLQ
94 ### What do RSA and ECDSA JWKs look like?
96 `keypairs` will generate either ECDSA or RSA at random and only support
97 NIST-approved, industry-standard key types and options.
101 `[ "crv", "d", "kty", "x", "y" ]`
106 "d": "hYmoRZJp8b98wl0Daw49R1NjHfDhGNXP34-QyaCuZIk",
108 "x": "5K5ALgtWw37KsZOrBdwCyGOGKCFd27u-t61dmUiieJY",
109 "y": "wr3BNL-CeqkGtiRVqo3yizKxUA0bwS1MNZeqytdwICA"
115 `[ "crv", "kid", "kty", "use", "x", "y" ]`
120 "kid": "jdxxYcSBeB_yGheiBUmx61txq1dacGXH__ulBnZVG0E",
123 "x": "5K5ALgtWw37KsZOrBdwCyGOGKCFd27u-t61dmUiieJY",
124 "y": "wr3BNL-CeqkGtiRVqo3yizKxUA0bwS1MNZeqytdwICA"
128 Note that `kid` is the thumbprint, and `use` is omitted when generating
133 `[ "d", "dp", "dq", "e", "kty", "n", "p", "q", "qi" ]`
137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WbuvlWZZVXHkCS9zRlNbzEa-zqMmvfrckNc7b3VBAm8Id5-hgrHLnSOc7qG8t5xDPAKiNMXf2_ya-eLmCIAPwI5GzMNxFmKyvxUCN2z9lMASrwvxtV9dX4bIExZToN7NQqxAZwgn6BgMsmR_l7olo8nsUfU",
144 "q": "8IJn1cQaellOe0zi5zWF4QGzfARtu-6vKMvNkGRlB6gws3j6pIzd54IXa6O2H7tMjsK0jDXi3Wh4M1IdcGxJHT9aPt9UIdlgW1zbLhN-DfQku-i1_bQ4vMZ6_kchpZsDRbCIQ290ZfWSTaYp5EtBGM359W-jAH2v-IYtCuN6GXU",
145 "qi": "XFoxKvgujg1fwRsUiaKb7ptTxboGPWjcjivP67Hk-T28JfevJoyQQk2YmLqQLZZFr5uZ-POIIP2GQd-k2yXDyPsZXXe0-QTY4t0g2HXHInE4meROfnqfNjsijBrNqEQz_mqs9714tQXNdjpOExSUceh2DpepaS1z73gsqwTqeWI"
151 `[ "e", "kid", "kty", "n", "use" ]`
156 "kid": "4GTGYg18yQLUndStAb65ZqPfDdWiBtYl4gzDZosSD38",
158 "n": "vm0SbK4I_4LwXrLU6PR69Y331HJNXNCdPvlD4EZMUCqjQj-M6F7lopWeXBQy93H06s1LnLfdaE1-gRQv0ptzDNaupObi1SOeZiSmqaXJ3sQl0l01i4FXYvUboRrQWWsqkDwh1Azth7sf4m5nNfhqK_D4jfmtYoOAL-DsFXJ2018amcKBuiesOPXl4rw2BoHQoTXJq7YfWKpDWnm6s6zXLubTmHG9jv7NUKqoqCen6NJMSTP40uKA2LjEnkbxw2JwKm0KlBPuLvkrYECwpUGzqYboXfrulif9TS9p5nWXM1dLKN1rN91zqGZw_idXs6ebJW3x47J9Ta9dvD5wqsRh-Q",
163 Note that `kid` is the thumbprint, and `use` is omitted when generating