Skip to content

Commit

Permalink
cryptojwt
Browse files Browse the repository at this point in the history
  • Loading branch information
peppelinux committed Mar 18, 2020
1 parent 68cf4bb commit 5571422
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.JWT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# https://tools.ietf.org/html/rfc7516
# https://cryptojwt.readthedocs.io/en/latest/


Create the RSA certificates
````
# Create RSA certificates
CERT_PATH='saml2_sp/saml2_config/certificates'
openssl req -nodes -new -x509 -days 3650 -keyout $CERT_PATH/key.pem -out $CERT_PATH/cert.pem
````

Encrypt
````
from cryptojwt.jwk.rsa import import_private_rsa_key_from_file
from cryptojwt.jwe.jwe_rsa import JWE_RSA
RSA_KEY_PATH = 'saml2_sp/saml2_config/certificates/key.pem'
priv_key = import_private_rsa_key_from_file(RSA_KEY_PATH)
pub_key = priv_key.public_key()
plain = b'Now is the time for all good men to come to the aid of ...'
_rsa = JWE_RSA(plain, alg="RSA1_5", enc="A128CBC-HS256")
jwe = _rsa.encrypt(pub_key)
````

Decrypt
````
from cryptojwt.jwe.jwe import factory
from cryptojwt.jwk.rsa import RSAKey
_decryptor = factory(jwe, alg="RSA1_5", enc="A128CBC-HS256")
_dkey = RSAKey(priv_key=priv_key)
msg = _decryptor.decrypt(jwe, [_dkey])
````

0 comments on commit 5571422

Please sign in to comment.