當前位置: 首頁>>代碼示例>>Python>>正文


Python base64.decodestring方法代碼示例

本文整理匯總了Python中base64.decodestring方法的典型用法代碼示例。如果您正苦於以下問題:Python base64.decodestring方法的具體用法?Python base64.decodestring怎麽用?Python base64.decodestring使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在base64的用法示例。


在下文中一共展示了base64.decodestring方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: parse_basic_auth

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import decodestring [as 別名]
def parse_basic_auth(src_ip_port, dst_ip_port, headers, authorization_header):
    '''
    Parse basic authentication over HTTP
    '''
    if authorization_header:
        # authorization_header sometimes is triggered by failed ftp
        try:
            header_val = headers[authorization_header.group()]
        except KeyError:
            return
        b64_auth_re = re.match('basic (.+)', header_val, re.IGNORECASE)
        if b64_auth_re != None:
            basic_auth_b64 = b64_auth_re.group(1)
            basic_auth_creds = base64.decodestring(basic_auth_b64)
            msg = 'Basic Authentication: %s' % basic_auth_creds
            printer(src_ip_port, dst_ip_port, msg) 
開發者ID:wi-fi-analyzer,項目名稱:3vilTwinAttacker,代碼行數:18,代碼來源:NetCreds.py

示例2: parse_netntlm_resp_msg

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import decodestring [as 別名]
def parse_netntlm_resp_msg(headers, resp_header, seq):
    '''
    Parse the client response to the challenge
    '''
    try:
        header_val3 = headers[resp_header]
    except KeyError:
        return
    header_val3 = header_val3.split(' ', 1)

    # The header value can either start with NTLM or Negotiate
    if header_val3[0] == 'NTLM' or header_val3[0] == 'Negotiate':
        try:
            msg3 = base64.decodestring(header_val3[1])
        except binascii.Error:
            return
        return parse_ntlm_resp(msg3, seq) 
開發者ID:wi-fi-analyzer,項目名稱:3vilTwinAttacker,代碼行數:19,代碼來源:NetCreds.py

示例3: parse_basic_auth

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import decodestring [as 別名]
def parse_basic_auth(src_ip_port, dst_ip_port, headers, authorization_header):
    '''
    Parse basic authentication over HTTP
    '''
    if authorization_header:
        # authorization_header sometimes is triggered by failed ftp
        try:
            header_val = headers[authorization_header.group()]
        except KeyError:
            return
        b64_auth_re = re.match('basic (.+)', header_val, re.IGNORECASE)
        if b64_auth_re != None:
            basic_auth_b64 = b64_auth_re.group(1)
            try:
                basic_auth_creds = base64.decodestring(basic_auth_b64)
            except Exception:
                return
            msg = 'Basic Authentication: %s' % basic_auth_creds
            printer(src_ip_port, dst_ip_port, msg) 
開發者ID:DanMcInerney,項目名稱:net-creds,代碼行數:21,代碼來源:net-creds.py

示例4: parse_netntlm_chal

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import decodestring [as 別名]
def parse_netntlm_chal(headers, chal_header, ack):
    '''
    Parse the netntlm server challenge
    https://code.google.com/p/python-ntlm/source/browse/trunk/python26/ntlm/ntlm.py
    '''
    try:
        header_val2 = headers[chal_header]
    except KeyError:
        return
    header_val2 = header_val2.split(' ', 1)
    # The header value can either start with NTLM or Negotiate
    if header_val2[0] == 'NTLM' or header_val2[0].lower() == 'negotiate':
        try:
            msg2 = header_val2[1]
        except IndexError:
            return
        msg2 = base64.decodestring(msg2)
        parse_ntlm_chal(msg2, ack) 
開發者ID:DanMcInerney,項目名稱:net-creds,代碼行數:20,代碼來源:net-creds.py

示例5: auth

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import decodestring [as 別名]
def auth(self, cookie):
        """
        Authenticate the cooke using the signature, verify that it
        has not expired; and return the cookie's content
        """
        decode = base64.decodestring(
            cookie.replace("_", "/").replace("~", "="))
        signature = decode[:_signature_size]
        expires = decode[_signature_size:_header_size]
        content = decode[_header_size:]
        if signature == hmac.new(self.secret, content, sha1).digest():
            if int(expires) > int(make_time(time.time())):
                return content
            else:
                # This is the normal case of an expired cookie; just
                # don't bother doing anything here.
                pass
        else:
            # This case can happen if the server is restarted with a
            # different secret; or if the user's IP address changed
            # due to a proxy.  However, it could also be a break-in
            # attempt -- so should it be reported?
            pass 
開發者ID:linuxscout,項目名稱:mishkal,代碼行數:25,代碼來源:cookie.py

示例6: base64_decode

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import decodestring [as 別名]
def base64_decode(input,errors='strict'):

    """ Decodes the object input and returns a tuple (output
        object, length consumed).

        input must be an object which provides the bf_getreadbuf
        buffer slot. Python strings, buffer objects and memory
        mapped files are examples of objects providing this slot.

        errors defines the error handling to apply. It defaults to
        'strict' handling which is the only currently supported
        error handling for this codec.

    """
    assert errors == 'strict'
    output = base64.decodestring(input)
    return (output, len(input)) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:19,代碼來源:base64_codec.py

示例7: base64_decode

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import decodestring [as 別名]
def base64_decode(nb):
    """Restore all bytes objects in the notebook from base64-encoded strings.
    
    Note: This is never used
    """
    for ws in nb.worksheets:
        for cell in ws.cells:
            if cell.cell_type == 'code':
                for output in cell.outputs:
                    if 'png' in output:
                        if isinstance(output.png, unicode):
                            output.png = output.png.encode('ascii')
                        output.png = decodestring(output.png)
                    if 'jpeg' in output:
                        if isinstance(output.jpeg, unicode):
                            output.jpeg = output.jpeg.encode('ascii')
                        output.jpeg = decodestring(output.jpeg)
    return nb 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:20,代碼來源:rwbase.py

示例8: test_read_jpeg

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import decodestring [as 別名]
def test_read_jpeg(self):
        """JPEG output data is b64 unicode"""
        s = writes(nb0)
        nb1 = nbjson.reads(s)
        found_jpeg = False
        for cell in nb1.worksheets[0].cells:
            if not 'outputs' in cell:
                continue
            for output in cell.outputs:
                if 'jpeg' in output:
                    found_jpeg = True
                    jpegdata = output['jpeg']
                    self.assertEqual(type(jpegdata), unicode)
                    # test that it is valid b64 data
                    b64bytes = jpegdata.encode('ascii')
                    raw_bytes = decodestring(b64bytes)
        assert found_jpeg, "never found jpeg output" 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:19,代碼來源:test_json.py

示例9: _handle_pyout

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import decodestring [as 別名]
def _handle_pyout(self, msg):
        """ Overridden to handle rich data types, like SVG.
        """
        if not self._hidden and self._is_from_this_session(msg):
            content = msg['content']
            prompt_number = content.get('execution_count', 0)
            data = content['data']
            metadata = msg['content']['metadata']
            if 'image/svg+xml' in data:
                self._pre_image_append(msg, prompt_number)
                self._append_svg(data['image/svg+xml'], True)
                self._append_html(self.output_sep2, True)
            elif 'image/png' in data:
                self._pre_image_append(msg, prompt_number)
                png = decodestring(data['image/png'].encode('ascii'))
                self._append_png(png, True, metadata=metadata.get('image/png', None))
                self._append_html(self.output_sep2, True)
            elif 'image/jpeg' in data and self._jpg_supported:
                self._pre_image_append(msg, prompt_number)
                jpg = decodestring(data['image/jpeg'].encode('ascii'))
                self._append_jpg(jpg, True, metadata=metadata.get('image/jpeg', None))
                self._append_html(self.output_sep2, True)
            else:
                # Default back to the plain text representation.
                return super(RichIPythonWidget, self)._handle_pyout(msg) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:27,代碼來源:rich_ipython_widget.py

示例10: from_json

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import decodestring [as 別名]
def from_json(self, json_input):
        # get the encoded json dump
        enc = json_input["matrix"]
        
        # build the numpy data type
        dataType = np.dtype(enc[0])
        
        # decode the base64 encoded numpy array data and create a new numpy array with this data & type
        dataArray = np.frombuffer(base64.decodestring(enc[1].encode('utf-8')), dataType)
        
        # if the array had more than one data set it has to be reshaped
        if len(enc) > 2:
             dataArray = dataArray.reshape(enc[2]) # return the reshaped numpy array containing several data sets
             
        self.matrix = np.matrix(dataArray) 
開發者ID:gcallah,項目名稱:indras_net,代碼行數:17,代碼來源:markov.py

示例11: from_json

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import decodestring [as 別名]
def from_json(cls, json_input):
        # get the encoded json dump
        enc = json_input["vector"]
        
        # build the numpy data type
        dataType = np.dtype(enc[0])

        # decode the base64 encoded numpy array data and create a new numpy array with this data & type
        return from_vector(np.frombuffer(base64.decodestring(enc[1].encode('utf-8')), dataType))

# Now we actually initialize the prehensions we declared above.
#  This can't be done earlier, since VectorSpace was just defined. 
開發者ID:gcallah,項目名稱:indras_net,代碼行數:14,代碼來源:vector_space.py

示例12: generate_jwt

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import decodestring [as 別名]
def generate_jwt(args):
    """Generates a signed JSON Web Token using a service account. Based on https://cloud.google.com/endpoints/docs/service-to-service-auth"""
    # Make sure the service account has "Service Account Token Creator" permissions in Google IAM
    credentials = ServiceAccountCredentials.from_json_keyfile_name(
      args.service_account_file).create_scoped(['https://www.googleapis.com/auth/cloud-platform'])

    service = googleapiclient.discovery.build(
        serviceName='iam', version='v1', credentials=credentials)

    now = int(time.time())
    header_json = json.dumps({
        "typ": "JWT",
        "alg": "RS256"})

    payload_json = json.dumps({
        'iat': now,
        "exp": now + 3600,
        'iss': args.issuer if args.issuer else credentials.service_account_email,
        "target_audience": 'https://' + args.aud,
        "aud": "https://www.googleapis.com/oauth2/v4/token"
    })

    header_and_payload = '{}.{}'.format(
        base64.urlsafe_b64encode(header_json),
        base64.urlsafe_b64encode(payload_json))
    slist = service.projects().serviceAccounts().signBlob(
        name="projects/-/serviceAccounts/" + credentials.service_account_email,
        body={'bytesToSign': base64.b64encode(header_and_payload)})
    res = slist.execute()
    signature = base64.urlsafe_b64encode(
        base64.decodestring(res['signature']))
    signed_jwt = '{}.{}'.format(header_and_payload, signature)

    return signed_jwt 
開發者ID:cloudendpoints,項目名稱:endpoints-tools,代碼行數:36,代碼來源:generate-google-id-jwt.py

示例13: read_data_block

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import decodestring [as 別名]
def read_data_block(encoding, endian, ordering, datatype, shape, data):
    """ Tries to unzip, decode, parse the funny string data """
    ord = array_index_order_codes.npcode[ordering]
    enclabel = gifti_encoding_codes.label[encoding]
    if enclabel == 'ASCII':
        # GIFTI_ENCODING_ASCII
        c = StringIO(data)
        da = np.loadtxt(c)
        da = da.astype(data_type_codes.type[datatype])
        # independent of the endianness
        return da
    elif enclabel == 'B64BIN':
        # GIFTI_ENCODING_B64BIN
        dec = base64.decodestring(data.encode('ascii'))
        dt = data_type_codes.type[datatype]
        sh = tuple(shape)
        newarr = np.fromstring(dec, dtype = dt)
        if len(newarr.shape) != len(sh):
            newarr = newarr.reshape(sh, order = ord)
    elif enclabel == 'B64GZ':
        # GIFTI_ENCODING_B64GZ
        # convert to bytes array for python 3.2
        # http://diveintopython3.org/strings.html#byte-arrays
        dec = base64.decodestring(data.encode('ascii'))
        zdec = zlib.decompress(dec)
        dt = data_type_codes.type[datatype]
        sh = tuple(shape)
        newarr = np.fromstring(zdec, dtype = dt)
        if len(newarr.shape) != len(sh):
            newarr = newarr.reshape(sh, order = ord)
    elif enclabel == 'External':
        # GIFTI_ENCODING_EXTBIN
        raise NotImplementedError("In what format are the external files?")
    else:
        return 0
    # check if we need to byteswap
    required_byteorder = gifti_endian_codes.byteorder[endian]
    if (required_byteorder in ('big', 'little') and
        required_byteorder != sys.byteorder):
        newarr = newarr.byteswap()
    return newarr 
開發者ID:ME-ICA,項目名稱:me-ica,代碼行數:43,代碼來源:parse_gifti_fast.py

示例14: construct_yaml_binary

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import decodestring [as 別名]
def construct_yaml_binary(self, node):
        try:
            value = self.construct_scalar(node).encode('ascii')
        except UnicodeEncodeError as exc:
            raise ConstructorError(None, None,
                    "failed to convert base64 data into ascii: %s" % exc,
                    node.start_mark)
        try:
            if hasattr(base64, 'decodebytes'):
                return base64.decodebytes(value)
            else:
                return base64.decodestring(value)
        except binascii.Error as exc:
            raise ConstructorError(None, None,
                    "failed to decode base64 data: %s" % exc, node.start_mark) 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:17,代碼來源:constructor.py

示例15: construct_python_bytes

# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import decodestring [as 別名]
def construct_python_bytes(self, node):
        try:
            value = self.construct_scalar(node).encode('ascii')
        except UnicodeEncodeError as exc:
            raise ConstructorError(None, None,
                    "failed to convert base64 data into ascii: %s" % exc,
                    node.start_mark)
        try:
            if hasattr(base64, 'decodebytes'):
                return base64.decodebytes(value)
            else:
                return base64.decodestring(value)
        except binascii.Error as exc:
            raise ConstructorError(None, None,
                    "failed to decode base64 data: %s" % exc, node.start_mark) 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:17,代碼來源:constructor.py


注:本文中的base64.decodestring方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。