【发布时间】:2016-04-10 19:29:18
【问题描述】:
我有这段代码,但是当我运行它时,它只接受某个长度的“to_address”变量。当它太长时,我收到一个异常:
Traceback (most recent call last):
** IDLE Internal Exception:
File "C:\Python27\lib\idlelib\run.py", line 325, in runcode
exec code in self.locals
File "C:\Python27\lib\idlelib\run.py", line 111, in main
seq, request = rpc.request_queue.get(block=True, timeout=0.05)
File "C:\Python27\lib\Queue.py", line 176, in get
raise Empty
Empty
这是我的代码:
import hashlib
import sqlite3
import socket
import time
from Crypto.PublicKey import RSA
# import keys
key_file = open('keys.pem','r')
key = RSA.importKey(key_file.read())
public_key = key.publickey()
private_key_readable = str(key.exportKey())
public_key_readable = str(key.publickey().exportKey())
address = hashlib.sha224(public_key_readable).hexdigest()
to_address = str(raw_input ("Send to address: "))
amount = str(raw_input ("How much to send: "))
timestamp = str(time.time())
transaction = str(timestamp) +":"+ str(address) +":"+ str(to_address) +":"+ str(amount)
signature = key.sign(transaction, '')
print "Client: Signature: "+str(signature)
if public_key.verify(transaction, signature) == True:
if int(amount) < 0:
print "Client: Signature OK, but cannot use negative amounts"
else:
...process...
else:
print "Client: Invalid signature"
raise
#enter transaction end
如果有人知道如何绕过这个长度限制,我们将不胜感激。我是否需要以某种方式加密字符串以使其更短以便验证它然后再次解密?
【问题讨论】:
标签: python rsa digital-signature pycrypto