Compute MD5 hash for bits and encode as Base64
    :param any data: data to compute MD5 for
    :rtype: str
    :return: MD5 for data
978318
def compute_md5_for_data_asbase64(data):
    # type: (obj) -> str
    
    hasher = blobxfer.util.new_md5_hasher()
    hasher.update(data)
    return blobxfer.util.base64_encode_as_string(hasher.digest())
643170
public static byte[] md5Hash(String data, Charset charset) throws NoSuchAlgorithmException {
		return md5Hash(data.getBytes(charset));
	}
9621
def binary_encode_any_high_ascii_in_hash(hash)
      Hash[hash.map { |key, value| [key, binary_encode_any_high_ascii(value)] }]
    end
411059
def _md5_compute(self, f):
        '''
        
        '''
        md5 = hashlib.md5()
        block_size = 16384
        f.seek(0, 2)
        remaining = f.tell()
        f.seek(0)

        while (remaining > block_size):
            data = f.read(block_size)
            remaining = remaining - block_size
            md5.update(data)

        if remaining > 0:
            data = f.read(remaining)
            md5.update(data)

        return md5.digest()
122065
def get_md5(self, filename):
        
        with open(filename, 'rb') as f:
            m = hashlib.md5(f.read())
        return m.hexdigest()
640465
def encode(data):
    
    res = ""
    for i in range(0,len(data), 3):
        if (i+2==len(data)):
            res += _encode3bytes(ord(data[i]), ord(data[i+1]), 0)
        elif (i+1==len(data)):
            res += _encode3bytes(ord(data[i]), 0, 0)
        else:
            res += _encode3bytes(ord(data[i]), ord(data[i+1]), ord(data[i+2]))
    return res
247974
def data_for_base58check_encoding
      data = BTC::Data.data_from_bytes([self.version]) + @data
      if @public_key_compressed
        data += BTC::Data.data_from_bytes([0x01])
      end
      return data
    end
58280
def decode_data(self, data):
        
        assert self.get_empty() is False
        assert self._data_encoded is True
        if self._block_allowed:
            data = self._decode_transfer_block_data(data)
        else:
            data = self._decode_transfer_data(data)
        return data
664056
def decode_base64_dict(data):
    ''' 

    '''
    b64 = base64.b64decode(data['__ndarray__'])
    array = np.copy(np.frombuffer(b64, dtype=data['dtype']))
    if len(data['shape']) > 1:
        array = array.reshape(data['shape'])
    return array
190547
def encode_data(data):
    '''
    
    '''
    if isinstance(data, (six.string_types, bytes)):
        return encode_string(data)
    elif isinstance(data, (six.integer_types, bool, float)):
        return data
    elif data is None:
        return data
    elif isinstance(data, list):
        return [encode_data(x) for x in data]
    elif isinstance(data, dict):
        return {k: encode_data(v) for k, v in data.items()}
    else:
        raise ValueError('Cannot encode data of type %s' % type(data))
448879
function md5(data, digest) {
            var hash = "";

            if (!digest) { digest = 'binary'; }

            if (digest === 'buffer') {
                digest = undefined;
                // todo: 不支持 buffer 类型的 hash
                return "";
            }

            if (typeof data === 'string') {
                switch (digest) {
                    case "binary":
                        return SparkMD5.hash(data, true);
                    case "hex":
                        return SparkMD5.hash(data);
                    case "base64":
                        return TableStore.util.hexToBase64(SparkMD5.hash(data));
                    default:
                        return "";
                }
            }
            else {  // array buffer
                switch (digest) {
                    case "binary":
                        return SparkMD5.ArrayBuffer.hash(data, true);
                    case "hex":
                        return SparkMD5.ArrayBuffer.hash(data);
                    case "base64":
                        return TableStore.util.hexToBase64(SparkMD5.ArrayBuffer.hash(data));
                    default:
                        return "";
                }
            }
        }
356320
def md5(self):
        
        hasher = hashlib.md5()
        for key in sorted(self.data.keys()):
            hasher.update(self.data[key].md5().encode('utf-8'))
        md5 = hasher.hexdigest()
        return md5
1175893
def binary_encode_any_high_ascii(object)
      case object
      when String
        binary_encode_if_any_high_ascii(object)
      when Hash
        binary_encode_any_high_ascii_in_hash(object)
      when Array
        binary_encode_any_high_ascii_in_array(object)
      else
        object
      end
    end
361603
def encode_b64(data):
    ''''''
    byte_string = data.encode('utf-8')
    encoded = base64.b64encode(byte_string)
    return encoded.decode('utf-8')
127250
def check_data_is_empty(data):
    # type: (bytes) -> bool
    
    contentmd5 = compute_md5_for_data_asbase64(data)
    datalen = len(data)
    if datalen == _MAX_PAGE_SIZE_BYTES:
        if contentmd5 == _EMPTY_MAX_PAGE_SIZE_MD5:
            return True
    else:
        data_chk = b'\0' * datalen
        if compute_md5_for_data_asbase64(data_chk) == contentmd5:
            return True
    return False
838573
def Decode(self, encoded_data):
    
    try:
      # TODO: replace by libuna implementation or equivalent. The behavior of
      # base64.b64decode() does not raise TypeError for certain invalid base64
      # data e.g. b'\x01\x02\x03\x04\x05\x06\x07\x08' these are silently
      # ignored.
      decoded_data = base64.b64decode(encoded_data)
    except (TypeError, binascii.Error) as exception:
      raise errors.BackEndError(
          'Unable to decode base64 stream with error: {0!s}.'.format(
              exception))

    return decoded_data, b''
1259959
def generate_hash(data: dict, token: str) -> str:
    
    secret = hashlib.sha256()
    secret.update(token.encode('utf-8'))
    sorted_params = collections.OrderedDict(sorted(data.items()))
    msg = '\n'.join("{}={}".format(k, v) for k, v in sorted_params.items() if k != 'hash')
    return hmac.new(secret.digest(), msg.encode('utf-8'), digestmod=hashlib.sha256).hexdigest()