Skip to main content

Appendix C. Examples

Appendix C. Examples

This appendix includes a set of examples that show the different features and message types that have been defined in this document. To make the examples easier to read, they are presented using the extended CBOR diagnostic notation (defined in [RFC8610]) rather than as a binary dump.

A GitHub project has been created at [GitHub-Examples] that contains not only the examples presented in this document, but a more complete set of testing examples as well. Each example is found in a JSON file that contains the inputs used to create the example, some of the intermediate values that can be used in debugging the example, and the output of the example presented both as a hex dump and in CBOR diagnostic notation format. Some of the examples at the site are designed to be failure-testing cases; these are clearly marked as such in the JSON file. If errors in the examples in this document are found, the examples on GitHub will be updated, and a note to that effect will be placed in the JSON file.

As noted, the examples are presented using CBOR's diagnostic notation. A Ruby-based tool exists that can convert between the diagnostic notation and binary. This tool can be installed with the command line:

gem install cbor-diag

The diagnostic notation can be converted into binary files using the following command line:

diag2cbor.rb < inputfile > outputfile

The examples can be extracted from the XML version of this document via an XPath expression, as all of the source code is tagged with the attribute type='cbor-diag'. (Depending on the XPath evaluator one is using, it may be necessary to deal with > as an entity.)

//sourcecode[@type='cbor-diag']/text()

C.1. Examples of Signed Messages

C.1.1. Single Signature

This example uses the following:

  • Signature Algorithm: ECDSA w/ SHA-256, Curve P-256

Size of binary file is 103 bytes

   98(
[
/ protected / h'',
/ unprotected / {},
/ payload / 'This is the content.',
/ signatures / [
[
/ protected h'a10126' / &lt;&lt; {
/ alg / 1:-7 / ECDSA 256 /
} >>,
/ unprotected / {
/ kid / 4:'11'
},
/ signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb
5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b
98f53afd2fa0f30a'
]
]
]
)

C.1.2. Multiple Signers

This example uses the following:

  • Signature Algorithm: ECDSA w/ SHA-256, Curve P-256

  • Signature Algorithm: ECDSA w/ SHA-512, Curve P-521

Size of binary file is 277 bytes

   98(
[
/ protected / h'',
/ unprotected / {},
/ payload / 'This is the content.',
/ signatures / [
[
/ protected h'a10126' / &lt;&lt; {
/ alg / 1:-7 / ECDSA 256 /
} >>,
/ unprotected / {
/ kid / 4:'11'
},
/ signature / h'e2aeafd40d69d19dfe6e52077c5d7ff4e408282cbefb
5d06cbf414af2e19d982ac45ac98b8544c908b4507de1e90b717c3d34816fe926a2b
98f53afd2fa0f30a'
],
[
/ protected h'a1013823' / &lt;&lt; {
/ alg / 1:-36 / ECDSA 521 /
} >> ,
/ unprotected / {
/ kid / 4:'[email protected]'
},
/ signature / h'00a2d28a7c2bdb1587877420f65adf7d0b9a06635dd1
de64bb62974c863f0b160dd2163734034e6ac003b01e8705524c5c4ca479a952f024
7ee8cb0b4fb7397ba08d009e0c8bf482270cc5771aa143966e5a469a09f613488030
c5b07ec6d722e3835adb5b2d8c44e95ffb13877dd2582866883535de3bb03d01753f
83ab87bb4f7a0297'
]
]
]
)

C.1.3. Signature with Criticality

This example uses the following:

* Signature Algorithm: ECDSA w/ SHA-256, Curve P-256

* There is a criticality marker on the "reserved" header parameter.

Size of binary file is 125 bytes

```text
98(
[
/ protected h'a2687265736572766564f40281687265736572766564' /
&lt;&lt; {
"reserved":false,
/ crit / 2:[
"reserved"
]
} >>,
/ unprotected / {},
/ payload / 'This is the content.',
/ signatures / [
[
/ protected h'a10126' / &lt;&lt; {
/ alg / 1:-7 / ECDSA 256 /
} >>,
/ unprotected / {
/ kid / 4:'11'
},
/ signature / h'3fc54702aa56e1b2cb20284294c9106a63f91bac658d
69351210a031d8fc7c5ff3e4be39445b1a3e83e1510d1aca2f2e8a7c081c7645042b
18aba9d1fad1bd9c'
]
]
]
)

C.2. Single Signer Examples

C.2.1. Single ECDSA Signature

This example uses the following:

  • Signature Algorithm: ECDSA w/ SHA-256, Curve P-256

Size of binary file is 98 bytes

   18(
[
/ protected h'a10126' / &lt;&lt; {
/ alg / 1:-7 / ECDSA 256 /
} >>,
/ unprotected / {
/ kid / 4:'11'
},
/ payload / 'This is the content.',
/ signature / h'8eb33e4ca31d1c465ab05aac34cc6b23d58fef5c083106c4
d25a91aef0b0117e2af9a291aa32e14ab834dc56ed2a223444547e01f11d3b0916e5
a4c345cacb36'
]
)

C.3. Examples of Enveloped Messages

C.3.1. Direct ECDH

This example uses the following:

  • CEK: AES-GCM w/ 128-bit key

  • Recipient class: ECDH Ephemeral-Static, Curve P-256

Size of binary file is 151 bytes

   96(
[
/ protected h'a10101' / &lt;&lt; {
/ alg / 1:1 / AES-GCM 128 /
} >>,
/ unprotected / {
/ iv / 5:h'c9cf4df2fe6c632bf7886413'
},
/ ciphertext / h'7adbe2709ca818fb415f1e5df66f4e1a51053ba6d65a1a0
c52a357da7a644b8070a151b0',
/ recipients / [
[
/ protected h'a1013818' / &lt;&lt; {
/ alg / 1:-25 / ECDH-ES + HKDF-256 /
} >>,
/ unprotected / {
/ ephemeral / -1:{
/ kty / 1:2,
/ crv / -1:1,
/ x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbf
bf054e1c7b4d91d6280',
/ y / -3:true
},
/ kid / 4:'[email protected]'
},
/ ciphertext / h''
]
]
]
)

C.3.2. Direct Plus Key Derivation

This example uses the following:

  • CEK: AES-CCM w/ 128-bit key, truncate the tag to 64 bits

  • Recipient class: Use HKDF on a shared secret with the following implicit fields as part of the context.

    • salt: "aabbccddeeffgghh"

    • PartyU identity: "lighting-client"

    • PartyV identity: "lighting-server"

    • Supplementary Public Other: "Encryption Example 02"

Size of binary file is 91 bytes

   96(
[
/ protected h'a1010a' / &lt;&lt; {
/ alg / 1:10 / AES-CCM-16-64-128 /
} >>,
/ unprotected / {
/ iv / 5:h'89f52f65a1c580933b5261a76c'
},
/ ciphertext / h'753548a19b1307084ca7b2056924ed95f2e3b17006dfe93
1b687b847',
/ recipients / [
[
/ protected h'a10129' / &lt;&lt; {
/ alg / 1:-10
} >>,
/ unprotected / {
/ salt / -20:'aabbccddeeffgghh',
/ kid / 4:'our-secret'
},
/ ciphertext / h''
]
]
]
)

C.3.3. Encrypted Content with External Data

This example uses the following:

  • CEK: AES-GCM w/ 128-bit key

  • Recipient class: ECDH Static-Static, Curve P-256 with AES Key Wrap

  • Externally Supplied AAD: h'0011bbcc22dd44ee55ff660077'

Size of binary file is 173 bytes

   96(
[
/ protected h'a10101' / &lt;&lt; {
/ alg / 1:1 / AES-GCM 128 /
} >> ,
/ unprotected / {
/ iv / 5:h'02d1f7e6f26c43d4868d87ce'
},
/ ciphertext / h'64f84d913ba60a76070a9a48f26e97e863e28529d8f5335
e5f0165eee976b4a5f6c6f09d',
/ recipients / [
[
/ protected / h'a101381f' / {
\ alg \ 1:-32 \ ECDH-SS+A128KW \
} / ,
/ unprotected / {
/ static kid / -3:'[email protected]',
/ kid / 4:'[email protected]',
/ U nonce / -22:h'0101'
},
/ ciphertext / h'41e0d76f579dbd0d936a662d54d8582037de2e366fd
e1c62'
]
]
]
)

C.4. Examples of Encrypted Messages

C.4.1. Simple Encrypted Message

This example uses the following:

  • CEK: AES-CCM w/ 128-bit key and a 64-bit tag

Size of binary file is 52 bytes

   16(
[
/ protected h'a1010a' / &lt;&lt; {
/ alg / 1:10 / AES-CCM-16-64-128 /
} >> ,
/ unprotected / {
/ iv / 5:h'89f52f65a1c580933b5261a78c'
},
/ ciphertext / h'5974e1b99a3a4cc09a659aa2e9e7fff161d38ce71cb45ce
460ffb569'
]
)

C.4.2. Encrypted Message with a Partial IV

This example uses the following:

  • CEK: AES-CCM w/ 128-bit key and a 64-bit tag

  • Prefix for IV is 89F52F65A1C580933B52

Size of binary file is 41 bytes

   16(
[
/ protected h'a1010a' / &lt;&lt; {
/ alg / 1:10 / AES-CCM-16-64-128 /
} >> ,
/ unprotected / {
/ partial iv / 6:h'61a7'
},
/ ciphertext / h'252a8911d465c125b6764739700f0141ed09192de139e05
3bd09abca'
]
)

C.5. Examples of MACed Messages

C.5.1. Shared Secret Direct MAC

This example uses the following:

  • MAC: AES-CMAC, 256-bit key, truncated to 64 bits

  • Recipient class: direct shared secret

Size of binary file is 57 bytes

   97(
[
/ protected h'a1010f' / &lt;&lt; {
/ alg / 1:15 / AES-CBC-MAC-256//64 /
} >> ,
/ unprotected / {},
/ payload / 'This is the content.',
/ tag / h'9e1226ba1f81b848',
/ recipients / [
[
/ protected / h'',
/ unprotected / {
/ alg / 1:-6 / direct /,
/ kid / 4:'our-secret'
},
/ ciphertext / h''
]
]
]
)

C.5.2. ECDH Direct MAC

This example uses the following:

  • MAC: HMAC w/SHA-256, 256-bit key

  • Recipient class: ECDH key agreement, two static keys, HKDF w/ context structure

Size of binary file is 214 bytes

   97(
[
/ protected h'a10105' / &lt;&lt; {
/ alg / 1:5 / HMAC 256//256 /
} >> ,
/ unprotected / {},
/ payload / 'This is the content.',
/ tag / h'81a03448acd3d305376eaa11fb3fe416a955be2cbe7ec96f012c99
4bc3f16a41',
/ recipients / [
[
/ protected h'a101381a' / &lt;&lt; {
/ alg / 1:-27 / ECDH-SS + HKDF-256 /
} >> ,
/ unprotected / {
/ static kid / -3:'[email protected]',
/ kid / 4:'[email protected]',
/ U nonce / -22:h'4d8553e7e74f3c6a3a9dd3ef286a8195cbf8a23d
19558ccfec7d34b824f42d92bd06bd2c7f0271f0214e141fb779ae2856abf585a583
68b017e7f2a9e5ce4db5'
},
/ ciphertext / h''
]
]
]
)

C.5.3. Wrapped MAC

This example uses the following:

  • MAC: AES-MAC, 128-bit key, truncated to 64 bits

  • Recipient class: AES Key Wrap w/ a preshared 256-bit key

Size of binary file is 109 bytes

   97(
[
/ protected h'a1010e' / &lt;&lt; {
/ alg / 1:14 / AES-CBC-MAC-128//64 /
} >> ,
/ unprotected / {},
/ payload / 'This is the content.',
/ tag / h'36f5afaf0bab5d43',
/ recipients / [
[
/ protected / h'',
/ unprotected / {
/ alg / 1:-5 / A256KW /,
/ kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037'
},
/ ciphertext / h'711ab0dc2fc4585dce27effa6781c8093eba906f227
b6eb0'
]
]
]
)

C.5.4. Multi-Recipient MACed Message

This example uses the following:

  • MAC: HMAC w/ SHA-256, 128-bit key

  • Recipient class: Uses two different methods.

    1. ECDH Ephemeral-Static, Curve P-521, AES Key Wrap w/ 128-bit key

    2. AES Key Wrap w/ 256-bit key

Size of binary file is 309 bytes

   97(
[
/ protected h'a10105' / &lt;&lt; {
/ alg / 1:5 / HMAC 256//256 /
} >> ,
/ unprotected / {},
/ payload / 'This is the content.',
/ tag / h'bf48235e809b5c42e995f2b7d5fa13620e7ed834e337f6aa43df16
1e49e9323e',
/ recipients / [
[
/ protected h'a101381c' / &lt;&lt; {
/ alg / 1:-29 / ECDH-ES+A128KW /
} >> ,
/ unprotected / {
/ ephemeral / -1:{
/ kty / 1:2,
/ crv / -1:3,
/ x / -2:h'0043b12669acac3fd27898ffba0bcd2e6c366d53bc4db
71f909a759304acfb5e18cdc7ba0b13ff8c7636271a6924b1ac63c02688075b55ef2
d613574e7dc242f79c3',
/ y / -3:true
},
/ kid / 4:'[email protected]'
},
/ ciphertext / h'339bc4f79984cdc6b3e6ce5f315a4c7d2b0ac466fce
a69e8c07dfbca5bb1f661bc5f8e0df9e3eff5'
],
[
/ protected / h'',
/ unprotected / {
/ alg / 1:-5 / A256KW /,
/ kid / 4:'018c0ae5-4d9b-471b-bfd6-eef314bc7037'
},
/ ciphertext / h'0b2c7cfce04e98276342d6476a7723c090dfdd15f9a
518e7736549e998370695e6d6a83b4ae507bb'
]
]
]
)

C.6. Examples of MAC0 Messages

C.6.1. Shared-Secret Direct MAC

This example uses the following:

  • MAC: AES-CMAC, 256-bit key, truncated to 64 bits

  • Recipient class: direct shared secret

Size of binary file is 37 bytes

   17(
[
/ protected h'a1010f' / &lt;&lt; {
/ alg / 1:15 / AES-CBC-MAC-256//64 /
} >> ,
/ unprotected / {},
/ payload / 'This is the content.',
/ tag / h'726043745027214f'
]
)

Note that this example uses the same inputs as Appendix C.5.1.

C.7. COSE Keys

C.7.1. Public Keys

This is an example of a COSE Key Set. This example includes the public keys for all of the previous examples.

In order, the keys are:

Size of binary file is 481 bytes

   [
{
-1:1,
-2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0
8551d',
-3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008
4d19c',
1:2,
2:'[email protected]'
},
{
-1:1,
-2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a
09eff',
-3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf
c117e',
1:2,
2:'11'
},
{
-1:3,
-2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de
7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8
f42ad',
-3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e
60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1
d9475',
1:2,
2:'[email protected]'
},
{
-1:1,
-2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91
d6280',
-3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf
822bb',
1:2,
2:'[email protected]'
}
]

C.7.2. Private Keys

This is an example of a COSE Key Set. This example includes the
private keys for all of the previous examples.

In order the keys are:

* An EC key with a kid of "[email protected]"

* An EC key with a kid of "11"

* An EC key with a kid of "[email protected]"

* A shared-secret key with a kid of "our-secret"

* An EC key with a kid of "[email protected]"

* A shared-secret key with kid "our-secret2"

* A shared-secret key with a kid of "018c0ae5-4d9b-471b-
bfd6-eef314bc7037"

Size of binary file is 816 bytes

```text
[
{
1:2,
2:'[email protected]',
-1:1,
-2:h'65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c0
8551d',
-3:h'1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd008
4d19c',
-4:h'aff907c99f9ad3aae6c4cdf21122bce2bd68b5283e6907154ad911840fa
208cf'
},
{
1:2,
2:'11',
-1:1,
-2:h'bac5b11cad8f99f9c72b05cf4b9e26d244dc189f745228255a219a86d6a
09eff',
-3:h'20138bf82dc1b6d562be0fa54ab7804a3a64b6d72ccfed6b6fb6ed28bbf
c117e',
-4:h'57c92077664146e876760c9520d054aa93c3afb04e306705db609030850
7b4d3'
},
{
1:2,
2:'[email protected]',
-1:3,
-2:h'0072992cb3ac08ecf3e5c63dedec0d51a8c1f79ef2f82f94f3c737bf5de
7986671eac625fe8257bbd0394644caaa3aaf8f27a4585fbbcad0f2457620085e5c8
f42ad',
-3:h'01dca6947bce88bc5790485ac97427342bc35f887d86d65a089377e247e
60baa55e4e8501e2ada5724ac51d6909008033ebc10ac999b9d7f5cc2519f3fe1ea1
d9475',
-4:h'00085138ddabf5ca975f5860f91a08e91d6d5f9a76ad4018766a476680b
55cd339e8ab6c72b5facdb2a2a50ac25bd086647dd3e2e6e99e84ca2c3609fdf177f
eb26d'
},
{
1:4,
2:'our-secret',
-1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4
27188'
},
{
1:2,
-1:1,
2:'[email protected]',
-2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91
d6280',
-3:h'f01400b089867804b8e9fc96c3932161f1934f4223069170d924b7e03bf
822bb',
-4:h'02d1f7e6f26c43d4868d87ceb2353161740aacf1f7163647984b522a848
df1c3'
},
{
1:4,
2:'our-secret2',
-1:h'849b5786457c1491be3a76dcea6c4271'
},
{
1:4,
2:'018c0ae5-4d9b-471b-bfd6-eef314bc7037',
-1:h'849b57219dae48de646d07dbb533566e976686457c1491be3a76dcea6c4
27188'
}
]