Beispiel #1
0
 def sign(self, msg: str,
          private_key: RSAPrivateKeyWithSerialization) -> str:
     signed = private_key.sign(msg.encode("ascii"),
                               padding=padding.PSS(
                                   mgf=padding.MGF1(hashes.SHA256()),
                                   salt_length=padding.PSS.MAX_LENGTH),
                               algorithm=hashes.SHA256())
     return binascii.b2a_base64(signed).decode("utf-8")
Beispiel #2
0
def sign(private_key: rsa.RSAPrivateKeyWithSerialization, msg: bytes) -> bytes:
    """
    Signs a message with a private key to provide proof of authenticity.

    :param private_key: The private key to sign the message with.
    :type private_key: :class:`rsa.RSAPrivateKeyWithSerialization`
    :param msg: The message to sign.
    :type msg: `str`
    :return: The signature.
    :rtype: `bytes`
    """
    return private_key.sign(msg, padding.PSS(
            mgf=padding.MGF1(hashes.SHA256()),
            salt_length=padding.PSS.MAX_LENGTH),
        hashes.SHA256())
def sign(private_key: RSAPrivateKeyWithSerialization, data: str) -> str:
    signature = private_key.sign(
        data=bytes(data, "utf-8"), padding=padding.PKCS1v15(), algorithm=hashes.SHA256()
    )
    sig = base64.b64encode(signature)
    return sig.decode()