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


Python rsa.PublicKey方法代碼示例

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


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

示例1: parse_cert

# 需要導入模塊: import rsa [as 別名]
# 或者: from rsa import PublicKey [as 別名]
def parse_cert(raw_bytes):
    result = CertInfo()

    certType = rfc2459.Certificate(); 
    cert, rest = decoder.decode(raw_bytes, asn1Spec=certType)
    subj_pub_key_bytes = frombits(cert.getComponentByName('tbsCertificate').getComponentByName('subjectPublicKeyInfo').getComponentByName('subjectPublicKey'))
    SUBJECT = cert.getComponentByName('tbsCertificate').getComponentByName('subject')
    for rdn in SUBJECT[0]:
        for nv in rdn: 
            name = nv.getComponentByName('type')
            value = nv.getComponentByName('value')
            # could pick up regular OUs too
            if name == rfc2459.id_at_organizationalUnitName:
                #print 'name: %s' % name
                #print 'value: [%s] (%s)' % (str(value).strip(), type(value))
                result.control_fields.append(str(value).strip())

    rsaType = rfc2437.RSAPublicKey();
    rsadata,rsadata_rest = decoder.decode(subj_pub_key_bytes, asn1Spec=rsaType)
    mod = rsadata.getComponentByName("modulus")
    pub_exp = rsadata.getComponentByName("publicExponent")
    result.pub_key = rsa.PublicKey(long(mod), long(pub_exp))

    return result 
開發者ID:nelenkov,項目名稱:aboot-parser,代碼行數:26,代碼來源:parse-aboot.py

示例2: __unpaddingRSA

# 需要導入模塊: import rsa [as 別名]
# 或者: from rsa import PublicKey [as 別名]
def __unpaddingRSA(self, publickkey_modulus, publickkey_exponent, message):
        def padMSG(message, target_length):
            message = message[::-1]
            max_msglength = target_length - 11
            msglength = len(message)
            padding = b''
            padding_length = target_length - msglength - 3
            for i in range(padding_length):
                padding += b'\x00'
            return b''.join([b'\x00\x00', padding, b'\x00', message])
        def encrypt(message, pubkey):
            keylength = rsa.common.byte_size(pubkey.n)
            padded = padMSG(message, keylength)
            payload = rsa.transform.bytes2int(padded)
            encrypted = rsa.core.encrypt_int(payload, pubkey.e, pubkey.n)
            block = rsa.transform.int2bytes(encrypted, keylength)
            return block
        m = int(publickkey_modulus, 16)
        e = int(publickkey_exponent, 16)
        rsa_pubkey = rsa.PublicKey(m, e)
        crypto = encrypt(message.encode('utf-8'), rsa_pubkey)
        return crypto.hex() 
開發者ID:CharlesPikachu,項目名稱:DecryptLogin,代碼行數:24,代碼來源:baidupan.py

示例3: genCertAndPriv

# 需要導入模塊: import rsa [as 別名]
# 或者: from rsa import PublicKey [as 別名]
def genCertAndPriv(certFile, privFile, e, n, d):
    e = E
    p = n - 1
    q = n - 1
    exp1 = e
    exp2 = d
    coef = e
    r = rsa.PrivateKey(n, e, d, p, q, exp1=e, exp2=e,coef=e)
    r.exp1 = 0
    r.exp2 = 0
    r.coef = 0
    r.p = 0
    r.q = 0
    open(privFile, 'wt').write(r.save_pkcs1())
    a =rsa.PublicKey(n,e)
    replaceKey(certFile,a._save_pkcs1_der()) 
開發者ID:preempt,項目名稱:credssp,代碼行數:18,代碼來源:gen_cmd.py

示例4: __crypt

# 需要導入模塊: import rsa [as 別名]
# 或者: from rsa import PublicKey [as 別名]
def __crypt(self, mail, passwd, RSA):
    message = (chr(len(RSA.sessionKey)) + RSA.sessionKey +
                   chr(len(mail)) + mail +
                   chr(len(passwd)) + passwd).encode('utf-8')

    pub_key = rsa.PublicKey(int(RSA.nvalue, 16), int(RSA.evalue, 16))
    crypto = rsa.encrypt(message, pub_key).encode('hex')

    return crypto 
開發者ID:CyberTKR,項目名稱:CyberTK-Self,代碼行數:11,代碼來源:Talk.py

示例5: addr_to_pubkey

# 需要導入模塊: import rsa [as 別名]
# 或者: from rsa import PublicKey [as 別名]
def addr_to_pubkey(address):
	return rsa.PublicKey(int(address, 16), 65537) 
開發者ID:sixstars,項目名稱:starctf2018,代碼行數:4,代碼來源:serve.py

示例6: generate_form_data

# 需要導入模塊: import rsa [as 別名]
# 或者: from rsa import PublicKey [as 別名]
def generate_form_data(nonce, pubkey, servertime, rsakv, username, password):
    rsa_public_key = int(pubkey, 16)
    key = rsa.PublicKey(rsa_public_key, 65537)
    message = str(servertime) + '\t' + str(nonce) + '\n' + str(password)
    passwd = rsa.encrypt(message, key)
    passwd = binascii.b2a_hex(passwd)
    username = urllib2.quote(username)
    username = base64.encodestring(username)
    form_data = {
        'entry': 'weibo',
        'gateway': '1',
        'from': '',
        'savestate': '7',
        'useticket': '1',
        'pagerefer': 'http://weibo.com/p/1005052679342531/home?from=page_100505&mod=TAB&pids=plc_main',
        'vsnf': '1',
        'su': username,
        'service': 'miniblog',
        'servertime': servertime,
        'nonce': nonce,
        'pwencode': 'rsa2',
        'rsakv': rsakv,
        'sp': passwd,
        'sr': '1366*768',
        'encoding': 'UTF-8',
        'prelt': '115',
        'url': 'http://weibo.com/ajaxlogin.php?framelogin=1&callback=parent.sinaSSOController.feedBackUrlCallBack',
        'returntype': 'META'
    }
    form_data = urllib.urlencode(form_data)
    return form_data 
開發者ID:buxiebug,項目名稱:hexo_weibo_image,代碼行數:33,代碼來源:weibo_util.py

示例7: get_pwd

# 需要導入模塊: import rsa [as 別名]
# 或者: from rsa import PublicKey [as 別名]
def get_pwd(password, servertime, nonce, pubkey):
    rsaPublickey = int(pubkey, 16)
    key = rsa.PublicKey(rsaPublickey,65537)#create public key
    message = str(servertime) + '\t' + str(nonce) + '\n' + str(password)#create clear text
    passwd = rsa.encrypt(message, key)#cipher text
    passwd = binascii.b2a_hex(passwd)#convert the cipher text into hexadecimal
    return passwd 
開發者ID:somethingx64,項目名稱:SinaMicroblog_Creeper-Spider_VerificationCode,代碼行數:9,代碼來源:userencode.py

示例8: _login

# 需要導入模塊: import rsa [as 別名]
# 或者: from rsa import PublicKey [as 別名]
def _login(self, email, passwordd, certificate=None, loginName=url.systemname):
        self._thriftTransport.targetPath(url.LINE_AUTH_QUERY_PATH)
        session_json = url.get_json(url.parseUrl(url.LINE_SESSION_LINE_QUERY_PATH))
        self.certificate = certificate
        session_key = session_json['session_key']
        message = (chr(len(session_key)) + session_key +
                   chr(len(email)) + email +
                   chr(len(passwordd)) + passwordd).encode('utf-8')
        keyname, n, e = session_json['rsa_key'].split(",")
        pub_key = rsa.PublicKey(int(n, 16), int(e, 16))
        crypto = rsa.encrypt(message, pub_key).encode('hex')
        self._thriftTransport.targetPath(url.LINE_AUTH_QUERY_PATH)
        result = self._client.loginWithIdentityCredentialForCertificate(
            IdentityProvider.LINE, keyname, crypto, True, '127.0.0.1', loginName, certificate)

        if result.type == 3:
            url._pincode = result.pinCode
            self.callback.Pinverified(url._pincode)
            getAccessKey = url.get_json(
                url.parseUrl(url.LINE_CERTIFICATE_PATH), allowHeader=True)
            self.verifier = getAccessKey['result']['verifier']
            result = self._client.loginWithVerifierForCerificate(self.verifier)
            self.certificate = result.certificate
            self.authToken = result.authToken
            self.urls.set_Headers('X-Line-Access', result.authToken)

            self._thriftTransport.setAccesskey(self.authToken)
            self.onLogin()
            self._thriftTransport.targetPath(url.LINE_API_QUERY_PATH_FIR)

        elif result.type == 2:
            pass

        elif result.type == 1:
            self.authToken = result.authToken
            self.urls.set_Headers('X-Line-Access', result.authToken)
            self._thriftTransport.setAccesskey(self.authToken)
            self.onLogin()
            self._thriftTransport.targetPath(url.LINE_API_QUERY_PATH_FIR) 
開發者ID:merkremont,項目名稱:LineVodka,代碼行數:41,代碼來源:LineApi.py

示例9: unpack_license_key

# 需要導入模塊: import rsa [as 別名]
# 或者: from rsa import PublicKey [as 別名]
def unpack_license_key(key_str, pubkey_args):
    """
    Decode a string of license key data produced by `pack_license_key`. In other
    words, this function is the inverse of `pack_...` above:

        data == unpack_license_key(pack_license_key(data, ...), ...)

    If the given string is not a valid key, `InvalidKey` is raised.

    The parameter `pubkey_args` is a dictionary containing values for the RSA
    fields "n" and "e". It can be generated with fbs's command `init_licensing`.
    """
    try:
        result = json.loads(key_str)
    except ValueError:
        raise InvalidKey() from None
    try:
        signature = result.pop('key')
    except KeyError:
        raise InvalidKey() from None
    try:
        signature_bytes = b64decode(signature.encode('ascii'))
    except ValueError:
        raise InvalidKey() from None
    try:
        rsa.verify(_dumpb(result), signature_bytes, PublicKey(**pubkey_args))
    except VerificationError:
        raise InvalidKey() from None
    return result 
開發者ID:mherrmann,項目名稱:fbs,代碼行數:31,代碼來源:licensing.py

示例10: encrypt_passwd

# 需要導入模塊: import rsa [as 別名]
# 或者: from rsa import PublicKey [as 別名]
def encrypt_passwd(passwd, pubkey, servertime, nonce):
    key = rsa.PublicKey(int(pubkey, 16), int('10001', 16))
    message = str(servertime) + '\t' + str(nonce) + '\n' + str(passwd)
    passwd = rsa.encrypt(message.encode('utf-8'), key)
    return binascii.b2a_hex(passwd) 
開發者ID:chaolongzhang,項目名稱:sinaWeibo,代碼行數:7,代碼來源:weibo_login.py

示例11: get_password

# 需要導入模塊: import rsa [as 別名]
# 或者: from rsa import PublicKey [as 別名]
def get_password(self):
        # 創建公鑰。
        key = rsa.PublicKey(int(self.pre_login_data[2], 16), 65537)
        # 先對 message 加密,然後將結果的每一個字節轉換為一個十六進製數。
        message = ('\t'.join([str(self.pre_login_data[0]), self.pre_login_data[1]]) + '\n' + self.raw_password).encode('utf-8')
        # print(message)

        self.password = binascii.b2a_hex(rsa.encrypt(message, key))
        # print(self.password) 
開發者ID:cuckootan,項目名稱:WeiboSpider,代碼行數:11,代碼來源:cookies.py

示例12: get_password

# 需要導入模塊: import rsa [as 別名]
# 或者: from rsa import PublicKey [as 別名]
def get_password(self, password, servertime, nonce, pubkey):
        rsaPublickey = int(pubkey, 16)
        key = rsa.PublicKey(rsaPublickey, 65537)
        message = str(servertime) + '\t' + str(nonce) + '\n' + str(password)
        message = message.encode("utf-8")
        passwd = rsa.encrypt(message, key)
        passwd = binascii.b2a_hex(passwd)
        return passwd 
開發者ID:niro8,項目名稱:weibo_crawler,代碼行數:10,代碼來源:weibo_search.py

示例13: get_password

# 需要導入模塊: import rsa [as 別名]
# 或者: from rsa import PublicKey [as 別名]
def get_password(password, servertime, nonce, pubkey):
    rsa_publickey = int(pubkey, 16)
    key = rsa.PublicKey(rsa_publickey, 65537)
    message = str(servertime) + '\t' + str(nonce) + '\n' + str(password)
    message = message.encode("utf-8")
    passwd = rsa.encrypt(message, key)
    passwd = binascii.b2a_hex(passwd)
    return passwd


# post data and get the next url 
開發者ID:SpiderClub,項目名稱:weibospider,代碼行數:13,代碼來源:login.py

示例14: encrypt_passwd

# 需要導入模塊: import rsa [as 別名]
# 或者: from rsa import PublicKey [as 別名]
def encrypt_passwd(passwd, pubkey, servertime, nonce):
        key = rsa.PublicKey(int(pubkey, 16), int('10001', 16))
        message = str(servertime) + '\t' + str(nonce) + '\n' + str(passwd)
        passwd = rsa.encrypt(message.encode('utf-8'), key)
        return binascii.b2a_hex(passwd) 
開發者ID:XJouYi,項目名稱:SinaWeibo,代碼行數:7,代碼來源:utils.py

示例15: get_crypt_password

# 需要導入模塊: import rsa [as 別名]
# 或者: from rsa import PublicKey [as 別名]
def get_crypt_password(self,message):
        rsaPublickey = int(self.key, 16)
        key = rsa.PublicKey(rsaPublickey, 65537)
        password = rsa.encrypt(message, key)
        password = binascii.b2a_hex(password)
        return password 
開發者ID:lb2281075105,項目名稱:Python-Spider,代碼行數:8,代碼來源:23 tuchongnet.py


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