def decimal_to_bytes(encoded): """ Converts a decimal encoded string to its byte representation. :param encoded: Decimal encoded string. :returns: Byte string. """ return long_to_bytes(long(encoded))
def long_to_base64(num): """ Base-64 encodes a long. :param num: A long integer. :returns: Base-64 encoded byte string. """ byte_string = long_to_bytes(num) return base64_encode(byte_string)
def sign(self, digest): """ Signs a digest with the key. :param digest: The SHA-1 digest of the data. :param encoder: The encoding method to use. Default EMSA-PKCS1-v1.5 :returns: Signature byte string. """ return long_to_bytes(self._sign(digest))
def pkcs1_v1_5_encode(key_size, data): """ Encodes a key using PKCS1's emsa-pkcs1-v1_5 encoding. Adapted from paramiko. :author: Rick Copeland <*****@*****.**> :param key_size: RSA key size. :param data: Data :returns: A blob of data as large as the key's N, using PKCS1's "emsa-pkcs1-v1_5" encoding. """ SHA1_DIGESTINFO = '\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14' size = len(long_to_bytes(key_size)) filler = '\xff' * (size - len(SHA1_DIGESTINFO) - len(data) - 3) return '\x00\x01' + filler + '\x00' + SHA1_DIGESTINFO + data