当前位置: 首页>>代码示例>>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;未经允许,请勿转载。