コード例 #1
0
 def __init__(self, amount, sender_public_key, recipient_public_key,
              sender_private_key):
     self.amount = amount
     self.sender = sender_public_key
     self.recipient = recipient_public_key
     self.sign, _ = sign_message(
         str(amount) + key_to_string(sender_public_key) +
         key_to_string(recipient_public_key), sender_private_key)
コード例 #2
0
from encode import encode,decode
import signature

# This is the test data to sign
data = 'test signed data'

# Generate a PyCrypto RSA key using signature module
key = signature.generate_key()

# Sign the test data with the key
sig = signature.sign(key, data)

# Dump encoded versions of the keys and data to the console
print 'private', signature.key_to_string(key)
print 'public', signature.key_to_string(key.publickey())
print 'address', signature.public_key_to_address(key.publickey())
print 'data', data
print 'signature', sig, '\n'

# Test verification code
print 'call to verify() with legit data\t\t\t%s\t(Should be True)' % signature.verify(key, sig, data)
print 'call of verify() with tampered data\t\t\t%s\t(Should be False)' % key.verify(data+'asdf',(decode(encode(sig),type='long'),None))
コード例 #3
0
 def privkey(self):
     return key_to_string(self.private_key)
コード例 #4
0
 def pubkey(self):
     return key_to_string(self.public_key)
コード例 #5
0
 def recipient_str(self):
     return key_to_string(self.recipient)
コード例 #6
0
 def sender_str(self):
     return key_to_string(self.sender)
コード例 #7
0
 def to_string(self):
     return str(self.amount) + key_to_string(self.sender) + key_to_string(
         self.recipient) + str(self.sign)
コード例 #8
0
 def valid(self):
     plaintext = str(self.amount) + key_to_string(
         self.sender) + key_to_string(self.recipient)
     Hash = SHA256.new(plaintext.encode()).digest()
     return verify_message(self.sign, Hash, self.sender)