def get_pwd_rsa(self, pwd, servertime, nonce):
"""
Get rsa2 encrypted password, using RSA module from https://pypi.python.org/pypi/rsa/3.1.1, documents can be accessed at
http://stuvel.eu/files/python-rsa-doc/index.html
"""
#n, n parameter of RSA public key, which is published by WEIBO.COM
#hardcoded here but you can also find it from values return from prelogin status above
weibo_rsa_n = 'EB2A38568661887FA180BDDB5CABD5F21C7BFD59C090CB2D245A87AC253062882729293E5506350508E7F9AA3BB77F4333231490F915F6D63C55FE2F08A49B353F444AD3993CACC02DB784ABBB8E42A9B1BBFFFB38BE18D78E87A0E41B9B8F73A928EE0CCEE1F6739884B9777E4FE9E88A1BBE495927AC4A799B3181D6442443'
#e, exponent parameter of RSA public key, WEIBO uses 0x10001, which is 65537 in Decimal
weibo_rsa_e = 65537
message = str(servertime) + '\t' + str(nonce) + '\n' + str(pwd)
#construct WEIBO RSA Publickey using n and e above, note that n is a hex string
key = rsa.PublicKey(int(weibo_rsa_n, 16), weibo_rsa_e)
#get encrypted password
encropy_pwd = rsa.encrypt(message, key)
#trun back encrypted password binaries to hex string
return binascii.b2a_hex(encropy_pwd)
python类PublicKey()的实例源码
def encrypt_password(p, st, nonce, pk, rsakv):
"""
Encrypting the password using rsa algorithm.
p: password
st: server time
nonce: random value
pk: public key
rsakv: rsa key value
"""
pk = '0x' + pk
pk = int(pk, 16)
msg = str(st) + '\t' + str(nonce) + '\n' + p
key = rsa.PublicKey(pk, 65537)
psw = rsa.encrypt(msg.encode("utf-8"), key)
psw = binascii.b2a_hex(psw)
return decode(psw)
def receive_hispubkey(mypub=None):
"""
Try to get his public key from clipboard, saved to "hispub"
return True if success else False
"""
if mypub is None:
mypub = storage_get("mypub")
try:
rawdata = clipboard_read()
hispub = d64(rawdata)
if not isinstance(hispub, rsa.PublicKey):
return False
if hispub == mypub:
return False # clipboard not changed
else:
storage_save("hispub",hispub)
return True,hispub
except:
return False
def get(self):
# checks if the user can create a new package entry
# if so, returns a new secret
# user then must post the signed package to this endpoint
if not ENGINE.check_package(request.form['owner'], request.form['package']):
# try to pull the users public key
query = ENGINE.get_key(request.form['owner'])
# in doing so, check if the user exists
if query == None:
return error_payload('Owner does not exist.')
# construct the user's public key
user_public_key = rsa.PublicKey(int(query[0]), int(query[1]))
# create a new secret
secret = random_string(53)
# sign and store it in the db so no plain text instance exists in the universe
server_signed_secret = str(rsa.encrypt(secret.encode('utf8'), KEY[0]))
query = ENGINE.set_secret(request.form['owner'], server_signed_secret)
# sign and send secret to user
user_signed_secret = rsa.encrypt(secret.encode('utf8'), user_public_key)
return success_payload(str(user_signed_secret), 'Package available to register.')
else:
return error_payload('Package already exists.')
def encrypt_passwd(self, 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)
def get_pwd_rsa(self, pwd, servertime, nonce):
"""
Get rsa2 encrypted password,
using RSA module from https://pypi.python.org/pypi/rsa/3.1.1,
documents can be accessed at
http://stuvel.eu/files/python-rsa-doc/index.html
"""
# n, n parameter of RSA public key,
# which is published by WEIBO.COM
# hardcoded here but you can also find
# it from values return from prelogin status above
weibo_rsa_n = ('EB2A38568661887FA180BDDB5CABD5F21C7BFD59C090'
'CB2D245A87AC253062882729293E5506350508E7F9AA'
'3BB77F4333231490F915F6D63C55FE2F08A49B353F44'
'4AD3993CACC02DB784ABBB8E42A9B1BBFFFB38BE18D7'
'8E87A0E41B9B8F73A928EE0CCEE1F6739884B9777E4F'
'E9E88A1BBE495927AC4A799B3181D6442443')
# e, exponent parameter of RSA public key,
# WEIBO uses 0x10001, which is 65537 in Decimal
weibo_rsa_e = 65537
message = str(servertime) + '\t' + str(nonce) + '\n' + str(pwd)
# construct WEIBO RSA Publickey using n and e above,
# note that n is a hex string
key = rsa.PublicKey(int(weibo_rsa_n, 16), weibo_rsa_e)
# get encrypted password
if six.PY3:
message = message.encode()
encropy_pwd = rsa.encrypt(message, key)
# trun back encrypted password binaries to hex string
sp = binascii.b2a_hex(encropy_pwd)
if six.PY3:
sp = sp.decode('utf-8')
return sp
def get_pwd_rsa(self, pwd, servertime, nonce):
"""
Get rsa2 encrypted password, using RSA module from https://pypi.python.org/pypi/rsa/3.1.1, documents can be accessed at
http://stuvel.eu/files/python-rsa-doc/index.html
"""
# n, n parameter of RSA public key, which is published by WEIBO.COM
#hardcoded here but you can also find it from values return from prelogin status above
#import pdb;pdb.set_trace()
weibo_rsa_n = 'EB2A38568661887FA180BDDB5CABD5F21C7BFD59C090CB2D245A87AC253062882729293E5506350508E7F9AA3BB77F4333231490F915F6D63C55FE2F08A49B353F444AD3993CACC02DB784ABBB8E42A9B1BBFFFB38BE18D78E87A0E41B9B8F73A928EE0CCEE1F6739884B9777E4FE9E88A1BBE495927AC4A799B3181D6442443'
#e, exponent parameter of RSA public key, WEIBO uses 0x10001, which is 65537 in Decimal
weibo_rsa_e = 65537
message = str(servertime) + '\t' + str(nonce) + '\n' + str(pwd)
#construct WEIBO RSA Publickey using n and e above, note that n is a hex string
key = rsa.PublicKey(int(weibo_rsa_n, 16), weibo_rsa_e)
#get encrypted password
if six.PY3:
message = message.encode()
encropy_pwd = rsa.encrypt(message, key)
#trun back encrypted password binaries to hex string
sp = binascii.b2a_hex(encropy_pwd)
if six.PY3:
sp = sp.decode('utf-8')
return sp
userencode.py 文件源码
项目:SinaMicroblog_Creeper-Spider_VerificationCode
作者: somethingx64
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
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
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
# ====================?????cookie====================
def get_sp(self, 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).decode('ascii')
def get_passwd(self, pubkey, servertime, nonce):
import rsa
rsaPublickey = int(pubkey, 16)
key = rsa.PublicKey(rsaPublickey, 65537) #????
message = str(servertime) + '\t' + str(nonce) + '\n' + str(self.password) #????js???????
passwd = rsa.encrypt(message, key) #??
passwd = binascii.b2a_hex(passwd) #????????16???
return passwd
def get_passwd(self, pubkey, servertime, nonce):
import rsa
rsaPublickey = int(pubkey, 16)
key = rsa.PublicKey(rsaPublickey, 65537) # ????
message = str(servertime) + '\t' + str(nonce) + '\n' + \
str(self.password) # ????js???????
passwd = rsa.encrypt(message, key) # ??
passwd = binascii.b2a_hex(passwd) # ????????16???
return passwd
def get_sp(self, 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).decode('ascii')
def get_sp(self, 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).decode('ascii')
def get_password(self, servertime, nonce, pubkey):
"""
get legal password, encrypt file: http://i.sso.sina.com.cn/js/ssologin.js
"""
string = (str(servertime) + '\t' + str(nonce) + '\n' + str(self.pass_word)).encode("utf-8")
public_key = rsa.PublicKey(int(pubkey, 16), int("10001", 16))
password = rsa.encrypt(string, public_key)
password = binascii.b2a_hex(password)
return password.decode()
def __init__(self, username, password, shared_secret):
self.session = requests.session()
self.resp = requests.post("https://store.steampowered.com" + "/login/getrsakey/", data={
"username": str(username),
}).json()
self.rsa_modulus = self.rsa_params(str(username)).get('rsa_mod')
self.rsa_exponent = self.rsa_params(str(username)).get('rsa_exp')
self.rsa_timestamp = self.rsa_params(str(username)).get('rsa_timestamp')
self.rsa_publickey = rsa.PublicKey(self.rsa_modulus, self.rsa_exponent)
self.encrypted_password = base64.b64encode(rsa.encrypt(str(password).encode('UTF-8'), self.rsa_publickey))
self.loginReq = self.loginRequest(str(username), self.encrypted_password, str(shared_secret))
def _set_public_key_string(self, public_key_string):
# remove PKCS#8 header if it exists
if public_key_string.startswith(PKCS8_HEADER):
public_key_string = public_key_string[len(PKCS8_HEADER):]
# add the appropriate PEM header/footer
public_key_string = self._add_pem_headers(public_key_string, "RSA PUBLIC KEY")
self._public_key = PYRSA.PublicKey.load_pkcs1(public_key_string)
def _set_private_key_string(self, private_key_string):
self._private_key = PYRSA.PrivateKey.load_pkcs1(private_key_string)
self._public_key = PYRSA.PublicKey(self._private_key.n, self._private_key.e)
def get_sp(self, 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).decode('ascii')
def get_password(password, servertime, nonce, pubkey):
rsaPublickey = int(pubkey, 16)
key = rsa.PublicKey(rsaPublickey, 65537) # ????,
message = str(servertime) + '\t' + str(nonce) + '\n' + str(password) # ????js???????
message = message.encode("utf-8")
passwd = rsa.encrypt(message, key) # ??
passwd = binascii.b2a_hex(passwd) # ????????16???
return passwd
def encode_pwd(self, password, servertime, nonce, pubkey):
rsaPublickey = int(pubkey, 16)
key = rsa.PublicKey(rsaPublickey, 65537) # ????
message = str(servertime) + '\t' + str(nonce) + '\n' + str(password) # ????js???????
passwd = rsa.encrypt(message, key) # ??
passwd = binascii.b2a_hex(passwd) # ????????16???
return passwd
# ????????
def get_password(self, servertime, nonce, pubkey):
"""
get legal password
"""
string = (str(servertime) + "\t" + str(nonce) + "\n" + str(self.pass_word)).encode("utf-8")
public_key = rsa.PublicKey(int(pubkey, 16), int("10001", 16))
password = rsa.encrypt(string, public_key)
password = binascii.b2a_hex(password)
return password.decode()
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
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
login.py 文件源码
项目:Analysis-of-Public-Opinion-Based-on-Microblogging-Reptile
作者: Yuzhen-Li
项目源码
文件源码
阅读 31
收藏 0
点赞 0
评论 0
def __get_spwd(self):
rsaPublickey = int(self.pubkey, 16)
key = rsa.PublicKey(rsaPublickey, 65537) #????
message = self.servertime + '\t' + self.nonce + '\n' + self.password #????js???????
passwd = rsa.encrypt(message, key) #??
passwd = binascii.b2a_hex(passwd) #????????16???
return passwd
def get_pwd(password, servertime, nonce, pubkey):
rsaPublickey = int(pubkey, 16)
key = rsa.PublicKey(rsaPublickey, 65537) #????
message = str(servertime) + '\t' + str(nonce) + '\n' + str(password) #???????????
passwd = rsa.encrypt(message, key) #??
passwd = binascii.b2a_hex(passwd) #????????16???
return passwd
def get_sp(password, pubkey, servertime, nonce):
# rsa??
key = rsa.PublicKey(int(pubkey, 16), 65537)
message = str(servertime) + '\t' + str(nonce) + '\n' + password
passwd = rsa.encrypt(message.encode("utf8"), key)
# ????????16??
sp = binascii.b2a_hex(passwd)
# print(sp)
return sp
# ?????
def enPass(self):
exponent = self.b64tohex(self.exponent)
modulus = self.b64tohex(self.modulus)
rsaKey = rsa.PublicKey(int(modulus, 16), int(exponent,16))
enPwd = binascii.b2a_hex(rsa.encrypt(self.pwd, rsaKey))
return self.hex2b64(enPwd)
def getSP(self):
n=self.pubKey
puk = rsa.PublicKey(int(
n,16), 65537)
#ct=ciphertext
ct=(str(self.servertime)+'\t'+str(self.nonce)+'\n'+str(self.p)).encode()
return binascii.b2a_hex(rsa.encrypt(ct, puk)).decode()
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)