def bytearray_to_base64(byte_array): """ Base-64 encodes a byte array. :param byte_array: The byte array. :returns: Base-64 encoded byte array without newlines. """ return base64_encode(bytearray_to_bytes(byte_array))
def long_to_bytes_original(num): """ Convert a long integer to a byte string:: long_to_bytes(n:long) : string :param num: Long value :returns: Byte string. """ byte_array = long_to_bytearray(num) return bytearray_to_bytes(byte_array)
def long_to_mpi(num): """ Converts a long value into an OpenSSL-format MPI Bignum byte string. :param num: Long value. :returns: OpenSSL-format MPI Bignum byte string. """ byte_array = long_to_bytearray(num) ext = 0 #If the high-order bit is going to be set, #add an extra byte of zeros if not (bit_count(num) & 0x7): ext = 1 length = byte_count(num) + ext byte_array = bytearray_concat(bytearray_create_zeros(4+ext), byte_array) byte_array[0] = (length >> 24) & 0xFF byte_array[1] = (length >> 16) & 0xFF byte_array[2] = (length >> 8) & 0xFF byte_array[3] = length & 0xFF return bytearray_to_bytes(byte_array)