本文整理汇总了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
示例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()
示例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())
示例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
示例5: addr_to_pubkey
# 需要导入模块: import rsa [as 别名]
# 或者: from rsa import PublicKey [as 别名]
def addr_to_pubkey(address):
return rsa.PublicKey(int(address, 16), 65537)
示例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
示例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
示例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)
示例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
示例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)
示例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)
示例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
示例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
示例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)
示例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