给定如下所示的公钥指数和模数,我如何加密字符串并将其作为文本发送到服务器?
publicKey: 10001,
modulus: 'd0eeaf178015d0418170055351711be1e4ed1dbab956603ac04a6e7a0dca1179cf33f90294782e9db4dc24a2b1d1f2717c357f32373fb3d9fd7dce91c40b6602'
Run Code Online (Sandbox Code Playgroud)
我正在尝试在python中复制javascript rsa库http://www.ohdave.com/rsa/提供的功能。在javascript中,它看起来像这样:
setMaxDigits(67); //sets a max digits for bigInt
var key = new RSAKeyPair('10001', '10001', 'd0eeaf178015d0418170055351711be1e4ed1dbab956603ac04a6e7a0dca1179cf33f90294782e9db4dc24a2b1d1f2717c357f32373fb3d9fd7dce91c40b6602');
var encrypted = encryptedString(key, 'message');
console.log(encrypted); //prints '88d58fec172269e5186592dd20446c594dbeb82c01edad41f841666500c9a530e24a282c6527ec66f4c826719f12478c6535bdc2baef86e4ff26906a26398413'
Run Code Online (Sandbox Code Playgroud)
我想有一种方法可以使用PyCrypto库执行此操作,但是我找不到任何使用指数和模数的示例。
使用下面的解决方案,它似乎正在工作。由于我使用的是python 2.7,因此将其修改为如下所示:
from Crypto.PublicKey.RSA import construct
from binascii import unhexlify
from codecs import encode
e = long(10001)
n = int(encode('d0eeaf17801.....5d041817005535171', 'hex'), 16)
key = construct((n, e))
a = key.encrypt('hello', None)
print(a)
('.X?\xdc\x81\xfb\x9b(\x0b\xa1\xc6\xf7\xc0\xa3\xd7}U{Q?\xa6VR\xbdJ\xe9\xc5\x1f\x
f9i+\xb2\xf7\xcc\x8c&_\x9bD\x00\x86}V[z&3\\]_\xde\xed\xdc~\xf2\xe1\xa9^\x96\xc3\
xd5R\xc2*\xcb\xd9\x1d\x88$\x98\xb0\x07\xfaG+>G#\xf7cG\xd8\xa6\xf3y_ 4\x17\x0b\x0
3z\x0cvk7\xf7\xebPyo-\xa1\x81\xf5\x81\xec\x17\x9e\xfe3j\x98\xf2\xd5\x80\x1d\xdd\
xaf\xa4\xc8I\xeeB\xdaP\x85\xa7',)
Run Code Online (Sandbox Code Playgroud)
现在,我想将此加密的文本转换为字符串,以通过发布请求发送。但这似乎不起作用:
a.decode('utf-8')
Run Code Online (Sandbox Code Playgroud) 完整的错误是:
AttributeError: Neither 'ColumnClause' object nor 'Comparator' object
has an attribute 'description'
Run Code Online (Sandbox Code Playgroud)
发生在 __ repr __ 中的 sqlalchemy\sql\elements.py 中的第 544 行
在 __ getattr__ 中的 sqlalchemy\sql\elements.py 中的第 735 行
我最初发现了这个问题,因为我的烧瓶模板(它遍历 ormobject.__ dict__以将数据输出到表中)没有显示特定的行。
深入python控制台并导入模块后,我通过尝试打印对象的属性来产生此错误。
from app.models import Parcel
o = Parcel.query.get(1)
o.parcelid #string field prints the correct value, no problem
o.yrbuilt #integer field, same, no problem
o.streetnum #string field, throws above error
Run Code Online (Sandbox Code Playgroud)
我的模型(db 变量是SQLAlchemy(app)):
class Parcel(db.Model):
"""
the county parcel data
"""
__tablename__ = 'parcel'
__table_args__ = …Run Code Online (Sandbox Code Playgroud) 我已经设置了一个 virtualenv 来运行一个 Flask 服务器。我已按照步骤设置 wfastcgi 以与 iis 一起使用。它似乎正在工作,因为我能够访问 python 应用程序,但是打印了一个 python 错误堆栈。
读取 WSGI 处理程序时出错:
Traceback (most recent call last):
File "c:\python27\lib\site-packages\wfastcgi.py", line 793, in main
env, handler = read_wsgi_handler(response.physical_path)
File "c:\python27\lib\site-packages\wfastcgi.py", line 635, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "c:\python27\lib\site-packages\wfastcgi.py", line 618, in get_wsgi_handler
raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb))
ValueError: "flask_app.application()" could not be imported: Traceback (most recent call last):
File "c:\python27\lib\site-packages\wfastcgi.py", line 602, in get_wsgi_handler
handler = __import__(module_name, fromlist=[name_list[0][0]])
File ".\flask_app.py", line 7, …Run Code Online (Sandbox Code Playgroud) 在python中有一种快速方法可以将值列表转换为命名变量吗?
例如:
row = ['files', 'file.pdf', 'D1234', 43]
folder = row[0]
name = row[1]
doc_id = row[2]
page_num = row[3]
Run Code Online (Sandbox Code Playgroud)