Skip to content

Instantly share code, notes, and snippets.

@dajiaji
Last active July 12, 2021 10:56
Show Gist options
  • Save dajiaji/0a1d60a211e6a8b42da58c7189dddf21 to your computer and use it in GitHub Desktop.
Save dajiaji/0a1d60a211e6a8b42da58c7189dddf21 to your computer and use it in GitHub Desktop.
A simple sample of signed CWT.
import cwt
from cwt import COSEKey
# The sender side:
private_key = COSEKey.from_jwk({
"kid": "01",
"kty": "OKP",
"key_ops": ["sign"],
"alg": "EdDSA",
"crv": "Ed25519",
"x": "2E6dX83gqD_D0eAmqnaHe1TC1xuld6iAKXfw2OVATr0",
"d": "L8JS08VsFZoZxGa9JvzYmCWOwg7zaKcei3KZmYsj7dc",
})
token = cwt.encode({"iss": "coaps://as.example", "sub": "dajiaji", "cti": "123"}, private_key)
# The recipient side:
public_key = COSEKey.from_jwk({
"kid": "01",
"kty": "OKP",
"key_ops": ["verify"],
"crv": "Ed25519",
"x": "2E6dX83gqD_D0eAmqnaHe1TC1xuld6iAKXfw2OVATr0",
})
decoded = cwt.decode(token, public_key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment