@@ -29,7 +29,7 @@ And then, you can use it as follows:
2929``` py
3030>> > import cwt
3131>> > from cwt import COSEKey
32- >> > key = COSEKey.from_symmetric_key (alg = " HS256" , kid = " 01" )
32+ >> > key = COSEKey.generate_symmetric_key (alg = " HS256" , kid = " 01" )
3333>> > token = cwt.encode({" iss" : " coaps://as.example" , " sub" : " dajiaji" , " cti" : " 123" }, key)
3434>> > token.hex()
3535' d18443a10105a05835a60172636f6170733a2f2f61732e657861' ...
@@ -101,7 +101,7 @@ Create a COSE MAC0 message, verify and decode it as follows:
101101``` py
102102from cwt import COSE , COSEKey
103103
104- mac_key = COSEKey.from_symmetric_key (alg = " HS256" , kid = " 01" )
104+ mac_key = COSEKey.generate_symmetric_key (alg = " HS256" , kid = " 01" )
105105
106106# The sender side:
107107sender = COSE .new(alg_auto_inclusion = True , kid_auto_inclusion = True )
@@ -117,7 +117,7 @@ Following two samples are other ways of writing the above example:
117117``` py
118118from cwt import COSE , COSEKey
119119
120- mac_key = COSEKey.from_symmetric_key (alg = " HS256" , kid = " 01" )
120+ mac_key = COSEKey.generate_symmetric_key (alg = " HS256" , kid = " 01" )
121121
122122# The sender side:
123123sender = COSE .new()
@@ -136,7 +136,7 @@ assert b"Hello world!" == recipient.decode(encoded, mac_key)
136136``` py
137137from cwt import COSE , COSEKey
138138
139- mac_key = COSEKey.from_symmetric_key (alg = " HS256" , kid = " 01" )
139+ mac_key = COSEKey.generate_symmetric_key (alg = " HS256" , kid = " 01" )
140140
141141# The sender side:
142142sender = COSE .new()
@@ -163,7 +163,7 @@ key distribution method.
163163``` py
164164from cwt import COSE , COSEKey, Recipient
165165
166- mac_key = COSEKey.from_symmetric_key (alg = " HS512" , kid = " 01" )
166+ mac_key = COSEKey.generate_symmetric_key (alg = " HS512" , kid = " 01" )
167167
168168# The sender side:
169169r = Recipient.from_jwk({" alg" : " direct" })
@@ -216,7 +216,7 @@ The AES key wrap algorithm can be used to wrap a MAC key as follows:
216216from cwt import COSE , COSEKey, Recipient
217217
218218# The sender side:
219- mac_key = COSEKey.from_symmetric_key (alg = " HS512" )
219+ mac_key = COSEKey.generate_symmetric_key (alg = " HS512" )
220220r = Recipient.from_jwk(
221221 {
222222 " kty" : " oct" ,
@@ -354,7 +354,7 @@ Create a COSE Encrypt0 message and decrypt it as follows:
354354``` py
355355from cwt import COSE , COSEKey
356356
357- enc_key = COSEKey.from_symmetric_key (alg = " ChaCha20/Poly1305" , kid = " 01" )
357+ enc_key = COSEKey.generate_symmetric_key (alg = " ChaCha20/Poly1305" , kid = " 01" )
358358
359359# The sender side:
360360nonce = enc_key.generate_nonce()
@@ -431,7 +431,7 @@ key distribution method.
431431``` py
432432from cwt import COSE , COSEKey, Recipient
433433
434- enc_key = COSEKey.from_symmetric_key (alg = " ChaCha20/Poly1305" , kid = " 01" )
434+ enc_key = COSEKey.generate_symmetric_key (alg = " ChaCha20/Poly1305" , kid = " 01" )
435435
436436# The sender side:
437437nonce = enc_key.generate_nonce()
@@ -489,7 +489,7 @@ The AES key wrap algorithm can be used to wrap a MAC key as follows:
489489from cwt import COSE , COSEKey, Recipient
490490
491491# A key to be wrapped
492- enc_key = COSEKey.from_symmetric_key (alg = " ChaCha20/Poly1305" )
492+ enc_key = COSEKey.generate_symmetric_key (alg = " ChaCha20/Poly1305" )
493493
494494# The sender side:
495495r = Recipient.from_jwk(
@@ -623,7 +623,7 @@ Create a COSE-HPKE Encrypt message and decrypt it as follows:
623623from cwt import COSE , COSEKey, Recipient
624624
625625# The sender side:
626- enc_key = COSEKey.from_symmetric_key (alg = " A128GCM" )
626+ enc_key = COSEKey.generate_symmetric_key (alg = " A128GCM" )
627627rpk = COSEKey.from_jwk(
628628 {
629629 " kty" : " EC" ,
@@ -761,7 +761,7 @@ import cwt
761761from cwt import Claims, COSEKey
762762
763763try :
764- key = COSEKey.from_symmetric_key (alg = " HS256" , kid = " 01" )
764+ key = COSEKey.generate_symmetric_key (alg = " HS256" , kid = " 01" )
765765 token = cwt.encode({" iss" : " coaps://as.example" , " sub" : " dajiaji" , " cti" : " 123" }, key)
766766 decoded = cwt.decode(token, key)
767767
@@ -790,7 +790,7 @@ A raw CWT structure (Dict[int, Any]) can also be used as follows:
790790import cwt
791791from cwt import COSEKey
792792
793- key = COSEKey.from_symmetric_key (alg = " HS256" , kid = " 01" )
793+ key = COSEKey.generate_symmetric_key (alg = " HS256" , kid = " 01" )
794794token = cwt.encode({1 : " coaps://as.example" , 2 : " dajiaji" , 7 : b " 123" }, key)
795795decoded = cwt.decode(token, key)
796796```
@@ -868,7 +868,7 @@ Create an encrypted CWT with `ChaCha20/Poly1305` and decrypt it as follows:
868868import cwt
869869from cwt import COSEKey
870870
871- enc_key = COSEKey.from_symmetric_key (alg = " ChaCha20/Poly1305" , kid = " 01" )
871+ enc_key = COSEKey.generate_symmetric_key (alg = " ChaCha20/Poly1305" , kid = " 01" )
872872token = cwt.encode({" iss" : " coaps://as.example" , " sub" : " dajiaji" , " cti" : " 123" }, enc_key)
873873decoded = cwt.decode(token, enc_key)
874874```
@@ -885,7 +885,7 @@ import cwt
885885from cwt import COSEKey
886886
887887# A shared encryption key.
888- enc_key = COSEKey.from_symmetric_key (alg = " ChaCha20/Poly1305" , kid = " enc-01" )
888+ enc_key = COSEKey.generate_symmetric_key (alg = " ChaCha20/Poly1305" , kid = " enc-01" )
889889
890890# Creates a CWT with ES256 signing.
891891with open (" ./private_key.pem" ) as key_file:
@@ -915,7 +915,7 @@ If you want to change the settings, you can create your own `CWT` class instance
915915``` py
916916from cwt import COSEKey, CWT
917917
918- key = COSEKey.from_symmetric_key (alg = " HS256" , kid = " 01" )
918+ key = COSEKey.generate_symmetric_key (alg = " HS256" , kid = " 01" )
919919mycwt = CWT .new(expires_in = 3600 * 24 , leeway = 10 )
920920token = mycwt.encode({" iss" : " coaps://as.example" , " sub" : " dajiaji" , " cti" : " 123" }, key)
921921decoded = mycwt.decode(token, key)
0 commit comments