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


Python encoder.encode方法代碼示例

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


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

示例1: _derive_keys

# 需要導入模塊: from pyasn1.codec.der import encoder [as 別名]
# 或者: from pyasn1.codec.der.encoder import encode [as 別名]
def _derive_keys(self, password=None):
        label = encode(self.encryption_oid) + encode(self.mac_oid)
        context = self.nonce.asOctets()
        backend = default_backend()

        kdf = KBKDFHMAC(
            algorithm=hashes.SHA256(),
            mode=Mode.CounterMode,
            length=48,
            rlen=4,
            llen=4,
            location=CounterLocation.BeforeFixed,
            label=label,
            context=context,
            fixed=None,
            backend=backend
        )

        key = kdf.derive(password)
        if self.DEBUG:
            sys.stderr.write("Derived key: {0}\n".format(key))

        self.encryption_key = key[0:16]
        self.mac_key = key[16:] 
開發者ID:fireeye,項目名稱:ADFSpoof,代碼行數:26,代碼來源:EncryptedPfx.py

示例2: check_dir

# 需要導入模塊: from pyasn1.codec.der import encoder [as 別名]
# 或者: from pyasn1.codec.der.encoder import encode [as 別名]
def check_dir(self, service, path, password = None):
        path = string.replace(path,'/', '\\')
        tid = self.tree_connect_andx('\\\\' + self.__remote_name + '\\' + service, password)
        try:
            smb = NewSMBPacket()
            smb['Tid'] = tid
            smb['Mid'] = 0

            cmd = SMBCommand(SMB.SMB_COM_CHECK_DIRECTORY)
            cmd['Parameters'] = ''
            cmd['Data'] = SMBCheckDirectory_Data(flags = self.__flags2)
            cmd['Data']['DirectoryName'] = path.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else path
            smb.addCommand(cmd)

            self.sendSMB(smb)

            while 1:
                s = self.recvSMB()
                if s.isValidAnswer(SMB.SMB_COM_CHECK_DIRECTORY):
                    return
        finally:
            self.disconnect_tree(tid) 
開發者ID:joxeankoret,項目名稱:CVE-2017-7494,代碼行數:24,代碼來源:smb.py

示例3: rmdir

# 需要導入模塊: from pyasn1.codec.der import encoder [as 別名]
# 或者: from pyasn1.codec.der.encoder import encode [as 別名]
def rmdir(self, service, path, password = None):
        path = string.replace(path,'/', '\\')
        # Check that the directory exists
        self.check_dir(service, path, password)

        tid = self.tree_connect_andx('\\\\' + self.__remote_name + '\\' + service, password)
        try:
            path = path.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else path

            smb = NewSMBPacket()
            smb['Tid'] = tid
            createDir = SMBCommand(SMB.SMB_COM_DELETE_DIRECTORY)
            createDir['Data'] = SMBDeleteDirectory_Data(flags=self.__flags2)
            createDir['Data']['DirectoryName'] = path
            smb.addCommand(createDir)

            self.sendSMB(smb)

            while 1:
                s = self.recvSMB()
                if s.isValidAnswer(SMB.SMB_COM_DELETE_DIRECTORY):
                    return
        finally:
            self.disconnect_tree(tid) 
開發者ID:joxeankoret,項目名稱:CVE-2017-7494,代碼行數:26,代碼來源:smb.py

示例4: mkdir

# 需要導入模塊: from pyasn1.codec.der import encoder [as 別名]
# 或者: from pyasn1.codec.der.encoder import encode [as 別名]
def mkdir(self, service, path, password = None):
        path = string.replace(path,'/', '\\')
        tid = self.tree_connect_andx('\\\\' + self.__remote_name + '\\' + service, password)
        try:
            path = path.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else path

            smb = NewSMBPacket()
            smb['Tid'] = tid
            smb['Mid'] = 0

            createDir = SMBCommand(SMB.SMB_COM_CREATE_DIRECTORY)
            createDir['Data'] = SMBCreateDirectory_Data(flags=self.__flags2)
            createDir['Data']['DirectoryName'] = path
            smb.addCommand(createDir)

            self.sendSMB(smb)

            smb = self.recvSMB()
            if smb.isValidAnswer(SMB.SMB_COM_CREATE_DIRECTORY):
                return 1
            return 0
        finally:
            self.disconnect_tree(tid) 
開發者ID:joxeankoret,項目名稱:CVE-2017-7494,代碼行數:25,代碼來源:smb.py

示例5: rename

# 需要導入模塊: from pyasn1.codec.der import encoder [as 別名]
# 或者: from pyasn1.codec.der.encoder import encode [as 別名]
def rename(self, service, old_path, new_path, password = None):
        old_path = string.replace(old_path,'/', '\\')
        new_path = string.replace(new_path,'/', '\\')
        tid = self.tree_connect_andx('\\\\' + self.__remote_name + '\\' + service, password)
        try:
            smb = NewSMBPacket()
            smb['Tid'] = tid
            smb['Mid'] = 0

            renameCmd = SMBCommand(SMB.SMB_COM_RENAME)
            renameCmd['Parameters'] = SMBRename_Parameters()
            renameCmd['Parameters']['SearchAttributes'] = ATTR_SYSTEM | ATTR_HIDDEN | ATTR_DIRECTORY
            renameCmd['Data'] = SMBRename_Data(flags = self.__flags2)
            renameCmd['Data']['OldFileName'] = old_path.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else old_path
            renameCmd['Data']['NewFileName'] = new_path.encode('utf-16le') if self.__flags2 & SMB.FLAGS2_UNICODE else new_path
            smb.addCommand(renameCmd)

            self.sendSMB(smb)

            smb = self.recvSMB()
            if smb.isValidAnswer(SMB.SMB_COM_RENAME):
               return 1
            return 0
        finally:
            self.disconnect_tree(tid) 
開發者ID:joxeankoret,項目名稱:CVE-2017-7494,代碼行數:27,代碼來源:smb.py

示例6: toTGT

# 需要導入模塊: from pyasn1.codec.der import encoder [as 別名]
# 或者: from pyasn1.codec.der.encoder import encode [as 別名]
def toTGT(self):
        tgt_rep = AS_REP()
        tgt_rep['pvno'] = 5
        tgt_rep['msg-type'] = int(constants.ApplicationTagNumbers.AS_REP.value)
        tgt_rep['crealm'] = self['server'].realm['data']

        # Fake EncryptedData
        tgt_rep['enc-part'] = None
        tgt_rep['enc-part']['etype'] = 1 
        tgt_rep['enc-part']['cipher'] = '' 
        seq_set(tgt_rep, 'cname', self['client'].toPrincipal().components_to_asn1)
        ticket = types.Ticket()
        ticket.from_asn1(self.ticket['data'])
        seq_set(tgt_rep,'ticket', ticket.to_asn1)

        cipher = crypto._enctype_table[self['key']['keytype']]()

        tgt = dict()
        tgt['KDC_REP'] = encoder.encode(tgt_rep)
        tgt['cipher'] = cipher
        tgt['sessionKey'] = crypto.Key(cipher.enctype, str(self['key']['keyvalue']))
        return tgt 
開發者ID:joxeankoret,項目名稱:CVE-2017-7494,代碼行數:24,代碼來源:ccache.py

示例7: _read_private_key

# 需要導入模塊: from pyasn1.codec.der import encoder [as 別名]
# 或者: from pyasn1.codec.der.encoder import encode [as 別名]
def _read_private_key(private_key_pem, passphrase=None):
    """Reads a private key PEM block and returns a RSAPrivatekey

    :param private_key_pem: The private key PEM block
    :param passphrase: Optional passphrase needed to decrypt the private key
    :returns: a RSAPrivatekey object
    """
    if passphrase and isinstance(passphrase, str):
        passphrase = passphrase.encode("utf-8")
    if isinstance(private_key_pem, str):
        private_key_pem = private_key_pem.encode('utf-8')

    try:
        return serialization.load_pem_private_key(private_key_pem, passphrase,
                                                  backends.default_backend())
    except Exception:
        LOG.exception("Passphrase required.")
        raise exceptions.NeedsPassphrase 
開發者ID:openstack,項目名稱:octavia,代碼行數:20,代碼來源:cert_parser.py

示例8: get_intermediates_pems

# 需要導入模塊: from pyasn1.codec.der import encoder [as 別名]
# 或者: from pyasn1.codec.der.encoder import encode [as 別名]
def get_intermediates_pems(intermediates=None):
    """Split the input string into individual x509 text blocks

    :param intermediates: PEM or PKCS7 encoded intermediate certificates
    :returns: A list of strings where each string represents an
              X509 pem block surrounded by BEGIN CERTIFICATE,
              END CERTIFICATE block tags
    """
    if isinstance(intermediates, str):
        try:
            intermediates = intermediates.encode("utf-8")
        except UnicodeDecodeError:
            LOG.debug("Couldn't encode intermediates string, it was probably "
                      "in binary DER format.")
    if X509_BEG in intermediates:
        for x509Pem in _split_x509s(intermediates):
            yield _prepare_x509_cert(_get_x509_from_pem_bytes(x509Pem))
    else:
        for x509Pem in _parse_pkcs7_bundle(intermediates):
            yield _prepare_x509_cert(_get_x509_from_der_bytes(x509Pem)) 
開發者ID:openstack,項目名稱:octavia,代碼行數:22,代碼來源:cert_parser.py

示例9: _process_pkcs7_substrate

# 需要導入模塊: from pyasn1.codec.der import encoder [as 別名]
# 或者: from pyasn1.codec.der.encoder import encode [as 別名]
def _process_pkcs7_substrate(substrate):
    contentInfo, _ = der_decoder.decode(substrate,
                                        asn1Spec=rfc2315.ContentInfo())

    contentType = contentInfo.getComponentByName('contentType')

    if contentType != rfc2315.signedData:
        raise Exception

    content, _ = der_decoder.decode(
        contentInfo.getComponentByName('content'),
        asn1Spec=rfc2315.SignedData())

    for blob in content.getComponentByName('certificates'):
        cert = x509.load_der_x509_certificate(der_encoder.encode(blob),
                                              backends.default_backend())
        print(cert.public_bytes(
            encoding=serialization.Encoding.PEM).decode(
            'unicode_escape'), end='')


# Main program code 
開發者ID:openstack,項目名稱:octavia,代碼行數:24,代碼來源:pkcs7_to_pem.py

示例10: toTGT

# 需要導入模塊: from pyasn1.codec.der import encoder [as 別名]
# 或者: from pyasn1.codec.der.encoder import encode [as 別名]
def toTGT(self):
        tgt_rep = AS_REP()
        tgt_rep['pvno'] = 5
        tgt_rep['msg-type'] = int(constants.ApplicationTagNumbers.AS_REP.value)
        tgt_rep['crealm'] = self['server'].realm['data']

        # Fake EncryptedData
        tgt_rep['enc-part'] = noValue
        tgt_rep['enc-part']['etype'] = 1
        tgt_rep['enc-part']['cipher'] = '' 
        seq_set(tgt_rep, 'cname', self['client'].toPrincipal().components_to_asn1)
        ticket = types.Ticket()
        ticket.from_asn1(self.ticket['data'])
        seq_set(tgt_rep,'ticket', ticket.to_asn1)

        cipher = crypto._enctype_table[self['key']['keytype']]()

        tgt = dict()
        tgt['KDC_REP'] = encoder.encode(tgt_rep)
        tgt['cipher'] = cipher
        tgt['sessionKey'] = crypto.Key(cipher.enctype, str(self['key']['keyvalue']))
        return tgt 
開發者ID:eth0izzle,項目名稱:cracke-dit,代碼行數:24,代碼來源:ccache.py

示例11: testDerCodec

# 需要導入模塊: from pyasn1.codec.der import encoder [as 別名]
# 或者: from pyasn1.codec.der.encoder import encode [as 別名]
def testDerCodec(self):
        substrate = pem.readBase64fromText(self.rsa_cert_pem_text)
        asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)

        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm']

        self.assertEqual(rfc3279.rsaEncryption, spki_a['algorithm'])

        spki_pk = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['subjectPublicKey'].asOctets()
        pk, rest = der_decoder(spki_pk, asn1Spec=rfc3279.RSAPublicKey())

        self.assertFalse(rest)
        self.assertTrue(pk.prettyPrint())
        self.assertEqual(spki_pk, der_encoder(pk))
        self.assertEqual(65537, pk['publicExponent'])
        self.assertEqual(rfc3279.sha1WithRSAEncryption,
                         asn1Object['tbsCertificate']['signature']['algorithm'])
        self.assertEqual(rfc3279.sha1WithRSAEncryption,
                         asn1Object['signatureAlgorithm']['algorithm']) 
開發者ID:etingof,項目名稱:pyasn1-modules,代碼行數:25,代碼來源:test_rfc3279.py

示例12: testOpenTypes

# 需要導入模塊: from pyasn1.codec.der import encoder [as 別名]
# 或者: from pyasn1.codec.der.encoder import encode [as 別名]
def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.dsa_cert_pem_text)
        asn1Object, rest = der_decoder(
            substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True)

        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm']

        self.assertEqual(rfc3279.id_dsa, spki_a['algorithm'])

        q_value = 1260916123897116834511257683105158021801897369967

        self.assertEqual(q_value, spki_a['parameters']['q']) 
開發者ID:etingof,項目名稱:pyasn1-modules,代碼行數:18,代碼來源:test_rfc3279.py

示例13: testDerCodec

# 需要導入模塊: from pyasn1.codec.der import encoder [as 別名]
# 或者: from pyasn1.codec.der.encoder import encode [as 別名]
def testDerCodec(self):
        substrate = pem.readBase64fromText(self.extn_pem_text)
        asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)

        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))
        self.assertEqual(rfc8649.id_ce_hashOfRootKey, asn1Object['extnID'])

        hashed_root_key, rest = der_decoder(
            asn1Object['extnValue'], rfc8649.HashedRootKey())

        self.assertFalse(rest)
        self.assertTrue(hashed_root_key.prettyPrint())
        self.assertEqual(asn1Object['extnValue'], der_encoder(hashed_root_key))
        self.assertEqual(
            rfc4055.id_sha512, hashed_root_key['hashAlg']['algorithm']) 
開發者ID:etingof,項目名稱:pyasn1-modules,代碼行數:19,代碼來源:test_rfc8649.py

示例14: testOpenTypes

# 需要導入模塊: from pyasn1.codec.der import encoder [as 別名]
# 或者: from pyasn1.codec.der.encoder import encode [as 別名]
def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.env_data_pem_text)
        asn1Object, rest = der_decoder(
            substrate, asn1Spec=self.asn1Spec, decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))
        
        self.assertIn(asn1Object['contentType'], rfc5652.cmsContentTypesMap.keys())
        kari_kea = asn1Object['content']['recipientInfos'][0]['kari']['keyEncryptionAlgorithm']
        self.assertEqual(rfc2876.id_kEAKeyEncryptionAlgorithm, kari_kea['algorithm'])
        self.assertEqual(rfc2876.id_fortezzaWrap80, kari_kea['parameters']['algorithm'])

        cea = asn1Object['content']['encryptedContentInfo']['contentEncryptionAlgorithm']
        self.assertEqual(rfc2876.id_fortezzaConfidentialityAlgorithm, cea['algorithm'])

        iv = univ.OctetString(hexValue='424f4755535f4956')
        self.assertEqual(iv, cea['parameters']['initialization-vector']) 
開發者ID:etingof,項目名稱:pyasn1-modules,代碼行數:20,代碼來源:test_rfc2876.py

示例15: testDerCodec

# 需要導入模塊: from pyasn1.codec.der import encoder [as 別名]
# 或者: from pyasn1.codec.der.encoder import encode [as 別名]
def testDerCodec(self):
        substrate = pem.readBase64fromText(self.smime_capabilities_pem_text)
        asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        found_wrap_alg = False
        for cap in asn1Object:
            if cap['capabilityID'] in rfc5751.smimeCapabilityMap.keys():
                if cap['parameters'].hasValue():
                    param, rest = der_decoder(
                        cap['parameters'],
                        asn1Spec=rfc5751.smimeCapabilityMap[cap['capabilityID']])
                    self.assertFalse(rest)
                    self.assertTrue(param.prettyPrint())
                    self.assertEqual(cap['parameters'], der_encoder(param))

                    if cap['capabilityID'] == rfc2876.id_kEAKeyEncryptionAlgorithm:
                        self.assertEqual(rfc2876.id_fortezzaWrap80, param['algorithm'])
                        found_wrap_alg = True

        self.assertTrue(found_wrap_alg) 
開發者ID:etingof,項目名稱:pyasn1-modules,代碼行數:25,代碼來源:test_rfc2876.py


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