Ejemplo n.º 1
0
def magic_envelope(raw_data, data_type, key):
    """Wrap the provided data in a magic envelope."""
    keypair = RSA.construct(
        (base64_to_long(key.mod.encode('utf-8')),
         base64_to_long(key.public_exponent.encode('utf-8')),
         base64_to_long(key.private_exponent.encode('utf-8'))))
    encoded_data = utils.encode(raw_data)
    signed = sign(encoded_data, keypair)
    return utils.create_magic_envelope(encoded_data, signed)
Ejemplo n.º 2
0
def magic_envelope(raw_data, data_type, key):
    """Wrap the provided data in a magic envelope."""
    logging.debug('Signing key: %s %s', key.public_exponent, key.mod)
    rsa = RSA.construct(
        (base64_to_long(key.mod.encode('utf-8')),
         base64_to_long(key.public_exponent.encode('utf-8')),
         base64_to_long(key.private_exponent.encode('utf-8'))))
    signed = sign(sig_plaintext(raw_data), rsa)
    return utils.create_magic_envelope(utils.encode(raw_data), signed)
Ejemplo n.º 3
0
def verify(author_uri, data, signed):
    """Verify that ``signed`` is ``data`` signed by ``author_uri``."""
    public_exp, mod = utils.get_public_key(author_uri)
    public_exp = base64_to_long(public_exp)
    mod = base64_to_long(mod)
    rsa = RSA.construct((public_exp, mod))
    data = utils.encode(data)
    putative = base64_to_long(signed.encode('utf-8'))
    esma = make_esma_msg(data, rsa)
    return rsa.verify(esma, (putative,))