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


Python encoder.encode方法代碼示例

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


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

示例1: send_dbman_msg

# 需要導入模塊: from pyasn1.codec.ber import encoder [as 別名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 別名]
def send_dbman_msg(self, opcode, msg):
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect((self.target_ip, self.dbman_port))

        encodedMsg = encoder.encode(msg, defMode=True)
        msgLen = len(encodedMsg)
        values = (opcode, msgLen, encodedMsg)
        s = struct.Struct(">ii%ds" % msgLen)
        packed_data = s.pack(*values)

        sock.send(packed_data)

        res = sock.recv(1024)
        if res is not None:
            print "Received 10002 response..."
        sock.close() 
開發者ID:tenable,項目名稱:poc,代碼行數:18,代碼來源:hp_imc_7_3_10002_download_backups.py

示例2: _handleControls

# 需要導入模塊: from pyasn1.codec.ber import encoder [as 別名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 別名]
def _handleControls(self, requestControls, responseControls):
        done = True
        if requestControls is not None:
            for requestControl in requestControls:
                if responseControls is not None:
                    for responseControl in responseControls:
                        if requestControl['controlType'] == CONTROL_PAGEDRESULTS:
                            if responseControl['controlType'] == CONTROL_PAGEDRESULTS:
                                if hasattr(responseControl, 'getCookie') is not True:
                                    responseControl = decoder.decode(encoder.encode(responseControl),
                                                                 asn1Spec=KNOWN_CONTROLS[CONTROL_PAGEDRESULTS]())[0]
                                if responseControl.getCookie():
                                    done = False
                                requestControl.setCookie(responseControl.getCookie())
                                break
                        else:
                            # handle different controls here
                            pass
        return done 
開發者ID:eth0izzle,項目名稱:cracke-dit,代碼行數:21,代碼來源:ldap.py

示例3: check_binary_sig

# 需要導入模塊: from pyasn1.codec.ber import encoder [as 別名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 別名]
def check_binary_sig(signature, boundary, content):
    """ Function checks for binary signature and replaces with base64"""
    # Check if the signature is base64 or not
    try:
        raw_sig = signature.get_payload().encode('ascii').strip()
    except UnicodeDecodeError:
        # If not decode to base64 and replace in raw message
        raw_sig = signature.get_payload().encode('base64').strip()

    signature.set_payload(raw_sig)
    content_pts = content.split(boundary)
    content_pts[-2] = '\r\n%s\r\n' % mimetostring(signature, 78)
    content = boundary.join(content_pts)

    # return the contents and raw signature
    return content, raw_sig 
開發者ID:abhishek-ram,項目名稱:pyas2,代碼行數:18,代碼來源:as2utils.py

示例4: updateusernameinencpart

# 需要導入模塊: from pyasn1.codec.ber import encoder [as 別名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 別名]
def updateusernameinencpart(key, rawticket, username, debug=False, verbose=False):
	try:
		ramticket, extra = decoder.decode(rawticket)
		serverticket = ramticket.getComponentByPosition(2)
		localticket = ramticket.getComponentByPosition(3)
		encserverticket = serverticket.getComponentByPosition(0).getComponentByPosition(3).getComponentByPosition(2).asOctets()
	except:
		raise ValueError('Unable to decode ticket. Invalid file.')
	if verbose: print('Ticket succesfully decoded')

	decserverticketraw, nonce = kerberos.decrypt(key, 2, encserverticket)

	a = decoder.decode(decserverticketraw)[0]
	a[3][1][0]._value = username
	e = encoder.encode(a)


	newencserverticket = kerberos.encrypt(key, 2, e, nonce)


	ramticket.getComponentByPosition(2).getComponentByPosition(0).getComponentByPosition(3).getComponentByPosition(2)._value = newencserverticket


	return ramticket 
開發者ID:nidem,項目名稱:kerberoast,代碼行數:26,代碼來源:kerberoast.py

示例5: getInternalValue

# 需要導入模塊: from pyasn1.codec.ber import encoder [as 別名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 別名]
def getInternalValue(self, sout, parent):
        """
        Return the internal value of this date element.  This
        value comes before any modifications such as packing,
        padding, truncating, etc.

        For Numbers this is the python int value.
        """

        if parent is None:
            return u""

        value = ""
        for c in self:
            if isinstance(c, DataElement):
                value = c.getValue()
                break

        if self.xmlNamespace is not None:
            attrib = "{%s}%s" % (self.xmlNamespace, self.attributeName)
        else:
            attrib = self.attributeName
        parent.set(attrib, value.decode('latin-1').encode('utf8'))

        return None 
開發者ID:MozillaSecurity,項目名稱:peach,代碼行數:27,代碼來源:dom.py

示例6: fingerprint

# 需要導入模塊: from pyasn1.codec.ber import encoder [as 別名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 別名]
def fingerprint(self):
        """
        Get the user presentation of the fingerprint of this L{Key}.  As
        described by U{RFC 4716 section
        4<http://tools.ietf.org/html/rfc4716#section-4>}::

            The fingerprint of a public key consists of the output of the MD5
            message-digest algorithm [RFC1321].  The input to the algorithm is
            the public key data as specified by [RFC4253].  (...)  The output
            of the (MD5) algorithm is presented to the user as a sequence of 16
            octets printed as hexadecimal with lowercase letters and separated
            by colons.

        @since: 8.2

        @return: the user presentation of this L{Key}'s fingerprint, as a
        string.

        @rtype: L{str}
        """
        return ':'.join([x.encode('hex') for x in md5(self.blob()).digest()]) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:23,代碼來源:keys.py

示例7: _preparePingPongData

# 需要導入模塊: from pyasn1.codec.ber import encoder [as 別名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 別名]
def _preparePingPongData(reqType, msgId, serial, secret):
    msg = Message()
    msg['version'] = PROTOCOL_VERSION
    msg['msg-id'] = msgId
    msg['content-id'] = reqType

    if msg['content-id'] == MSG_TYPE_PING:
        r = Ping()
    elif msg['content-id'] == MSG_TYPE_PONG:
        r = Pong()
    else:
        raise SnmpfwdError('not a ping-pong message')

    r['serial'] = serial

    msg['payload'] = encoder.encode(r)
    if secret:
        msg['payload'] = crypto.encrypt(secret, encoder.encode(r))
    else:
        msg['payload'] = encoder.encode(r)
    return encoder.encode(msg) 
開發者ID:etingof,項目名稱:snmpfwd,代碼行數:23,代碼來源:protocol.py

示例8: compress_payload

# 需要導入模塊: from pyasn1.codec.ber import encoder [as 別名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 別名]
def compress_payload(payload):
    cdata_attr = CompressedDataAttr()
    cdata_attr.setComponentByName('compressionAlgorithm', (1, 2, 840, 113549, 1, 9, 16, 3, 8))
    cdata_payload = CompressedDataPayload()
    cdata_payload.setComponentByName('content-type', (1, 2, 840, 113549, 1, 7, 1))
    cdata_payload.setComponentByName('content',
                                     Content(univ.OctetString(hexValue=zlib.compress(payload).encode('hex'))))
    cdata = CompressedData()
    cdata.setComponentByName('version', 0)
    cdata.setComponentByName('attributes', cdata_attr)
    cdata.setComponentByName('payload', cdata_payload)
    cdata_main = CompressedDataMain()
    cdata_main.setComponentByName('id-ct-compressedData', (1, 2, 840, 113549, 1, 9, 16, 1, 9))
    cdata_main.setComponentByName('compressedData', cdata)
    return encoder.encode(cdata_main, defMode=False).encode('base64') 
開發者ID:abhishek-ram,項目名稱:pyas2,代碼行數:17,代碼來源:as2utils.py

示例9: send

# 需要導入模塊: from pyasn1.codec.ber import encoder [as 別名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 別名]
def send(self, request, controls=None):
        message = LDAPMessage()
        message['messageID'] = self._messageId
        message['protocolOp'].setComponentByType(request.getTagSet(), request)
        if controls is not None:
            message['controls'].setComponents(*controls)

        data = encoder.encode(message)

        return self._socket.sendall(data) 
開發者ID:joxeankoret,項目名稱:CVE-2017-7494,代碼行數:12,代碼來源:ldap.py

示例10: encodeControlValue

# 需要導入模塊: from pyasn1.codec.ber import encoder [as 別名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 別名]
def encodeControlValue(self):
        self['controlValue'] = encoder.encode(SimplePagedResultsControlValue().setComponents(self._size, self._cookie)) 
開發者ID:joxeankoret,項目名稱:CVE-2017-7494,代碼行數:4,代碼來源:ldapasn1.py

示例11: encodeControlValue

# 需要導入模塊: from pyasn1.codec.ber import encoder [as 別名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 別名]
def encodeControlValue(self):
        self['controlValue'] = encoder.encode(
            SDFlagsControlValue().setComponents(self.flags)) 
開發者ID:eth0izzle,項目名稱:cracke-dit,代碼行數:5,代碼來源:ldapasn1.py

示例12: fromString

# 需要導入模塊: from pyasn1.codec.ber import encoder [as 別名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 別名]
def fromString(cls, data, type=None, passphrase=None):
        """
        Return a Key object corresponding to the string data.
        type is optionally the type of string, matching a _fromString_*
        method.  Otherwise, the _guessStringType() classmethod will be used
        to guess a type.  If the key is encrypted, passphrase is used as
        the decryption key.

        @type data: L{bytes}
        @param data: The key data.

        @type type: L{str} or L{None}
        @param type: A string describing the format the key data is in, or
        L{None} to attempt detection of the type.

        @type passphrase: L{bytes} or L{None}
        @param passphrase: The passphrase the key is encrypted with, or L{None}
        if there is no encryption.

        @rtype: L{Key}
        @return: The loaded key.
        """
        if isinstance(data, unicode):
            data = data.encode("utf-8")
        if isinstance(passphrase, unicode):
            passphrase = passphrase.encode("utf-8")
        if type is None:
            type = cls._guessStringType(data)
        if type is None:
            raise BadKeyError('cannot guess the type of %r' % (data,))
        method = getattr(cls, '_fromString_%s' % (type.upper(),), None)
        if method is None:
            raise BadKeyError('no _fromString method for %s' % (type,))
        if method.__code__.co_argcount == 2:  # No passphrase
            if passphrase:
                raise BadKeyError('key not encrypted')
            return method(data)
        else:
            return method(data, passphrase) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:41,代碼來源:keys.py

示例13: sshType

# 需要導入模塊: from pyasn1.codec.ber import encoder [as 別名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 別名]
def sshType(self):
        """
        Get the type of the object we wrap as defined in the SSH protocol,
        defined in RFC 4253, Section 6.6. Currently this can only be b'ssh-rsa',
        b'ssh-dss' or b'ecdsa-sha2-[identifier]'.

        identifier is the standard NIST curve name

        @return: The key type format.
        @rtype: L{bytes}
        """
        if self.type() == 'EC':
            return b'ecdsa-sha2-' + _secToNist[self._keyObject.curve.name.encode('ascii')]
        else:
            return {'RSA': b'ssh-rsa', 'DSA': b'ssh-dss'}[self.type()] 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:17,代碼來源:keys.py

示例14: toString

# 需要導入模塊: from pyasn1.codec.ber import encoder [as 別名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 別名]
def toString(self, type, extra=None):
        """
        Create a string representation of this key.  If the key is a private
        key and you want the representation of its public key, use
        C{key.public().toString()}.  type maps to a _toString_* method.

        @param type: The type of string to emit.  Currently supported values
            are C{'OPENSSH'}, C{'LSH'}, and C{'AGENTV3'}.
        @type type: L{str}

        @param extra: Any extra data supported by the selected format which
            is not part of the key itself.  For public OpenSSH keys, this is
            a comment.  For private OpenSSH keys, this is a passphrase to
            encrypt with.
        @type extra: L{bytes} or L{unicode} or L{None}

        @rtype: L{bytes}
        """
        if isinstance(extra, unicode):
            extra = extra.encode("utf-8")
        method = getattr(self, '_toString_%s' % (type.upper(),), None)
        if method is None:
            raise BadKeyError('unknown key type: %s' % (type,))
        if method.__code__.co_argcount == 2:
            return method(extra)
        else:
            return method() 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:29,代碼來源:keys.py

示例15: custom_asn1_marshal

# 需要導入模塊: from pyasn1.codec.ber import encoder [as 別名]
# 或者: from pyasn1.codec.ber.encoder import encode [as 別名]
def custom_asn1_marshal(values):
    return encode(values, asn1Spec=Record()) 
開發者ID:Tribler,項目名稱:py-ipv8,代碼行數:4,代碼來源:proofs.py


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