Skip to content

Instantly share code, notes, and snippets.

@4poc
Last active December 13, 2016 10:31
Show Gist options
  • Save 4poc/890fa12f5f0cd23f338ad1be9406023f to your computer and use it in GitHub Desktop.
Save 4poc/890fa12f5f0cd23f338ad1be9406023f to your computer and use it in GitHub Desktop.
Is this secure? (encrypted and signed(?))
import jose
from json import dumps
from Crypto.PublicKey import RSA
key = RSA.generate(2048)
private_key = key.exportKey('PEM').decode('utf-8')
public_key = key.publickey().exportKey('PEM').decode('utf-8')
from jwcrypto import jwk, jwe
from jwcrypto.common import json_encode
payload = {
'url': 'https://jwcrypto.readthedocs.io/en/stable/jwe.html#examples',
'user': 'asdfasdfasdf asdf saa sd fdas'
}
jwk_public_key = jwk.JWK.from_pem(bytes(public_key, 'utf-8'))
jwetoken = jwe.JWE(dumps(payload), json_encode({'alg': 'RSA-OAEP', 'enc': 'A128CBC-HS256'}))
jwetoken.add_recipient(jwk_public_key)
encrypted = jwetoken.serialize(True) # True for compact
var jose = require('node-jose');
const keystore = jose.JWK.createKeyStore();
const private_key = ...;
keystore.add(private_key, 'pem').
then((result) => {
console.log(result);
jose.JWE.createDecrypt(keystore).
decrypt(payload).
then((result) => {
console.log(result.plaintext.toString());
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment