Beispiel #1
0
def pk_sign(message: bytes, private_key: rsa.RSAPrivateKey) -> bytes:
    """
    Sign a message using RSASSA-PSS.
    """
    signer = private_key.signer(padding.PSS(padding.MGF1(hashes.SHA256()),
            padding.PSS.MAX_LENGTH),
        hashes.SHA256())
    signer.update(message)
    return signer.finalize()
Beispiel #2
0
def pk_sign(message: bytes, private_key: rsa.RSAPrivateKey) -> bytes:
    """
    Sign a message using RSASSA-PSS.
    """
    signer = private_key.signer(
        padding.PSS(padding.MGF1(hashes.SHA256()), padding.PSS.MAX_LENGTH),
        hashes.SHA256())
    signer.update(message)
    return signer.finalize()
Beispiel #3
0
async def sign_dictionary(
    private_key: rsa.RSAPrivateKey,
    dictionary: Dict[str, Any],
) -> bytes:
    """
    Takes a dict and returns a rsa signature of the hash of the dict

    :param private_key: RSA private_key
    :param dictionary: the dictionary to sign
    :return: signature of the dictionary
    """
    signature_interface = private_key.signer(
        padding.PSS(
            mgf=padding.MGF1(hashes.SHA256()),
            salt_length=padding.PSS.MAX_LENGTH,
        ),
        hashes.SHA256(),
    )

    signature_interface.update(await hash(bencode.encode(dictionary)))
    return signature_interface.finalize()