예제 #1
0
 def testStringConversion(self):
     privateKey1 = PrivateKey()
     string = privateKey1.toString()
     privateKey2 = PrivateKey.fromString(fromLatin(string))
     self.assertEqual(privateKey1.secret, privateKey2.secret)
     self.assertEqual(privateKey1.curve, privateKey2.curve)
예제 #2
0
    print("1 - Generate new keys")
    print("2 - Write message")
    print("3 - Sign message")
    print("4 - Verify signature")
    print("5 - Finish")
    print("-------------------------------------\n")
    
    option = int(input("Option:"))
    print(' ')

    if option == 1:
        privateKey = PrivateKey()
        publicKey = privateKey.publicKey()
        
        f_privateKey = open("privateKey.txt", "w")
        f_privateKey.write(privateKey.toString())
        f_privateKey.close()

        f_publicKey = open("publicKey.txt", "w")
        f_publicKey.write(publicKey.toString())
        f_publicKey.close()

        print('Private Key: ' + privateKey.toString())
        print('Public Key: ' + publicKey.toString())
    elif option == 2:
        message = str(input("Message: "))
    
    elif option == 3:
        if message != None:
            print('Select key to sign the message')
            print("1 - private key")
예제 #3
0
from ellipticcurve.ecdsa import Ecdsa
from ellipticcurve.privateKey import PrivateKey

# Generate new Keys
privateKey = PrivateKey()
print('PRIVATE KEY', privateKey.toString())
publicKey1 = privateKey.publicKey()
publicKey2 = privateKey.publicKey()
print('PUBLIC1', publicKey1)
print('PUBLIC2', publicKey2.toString())

message = "My test message"

# Generate Signature
signature = Ecdsa.sign(message, privateKey)
print('SIGNATURE', signature)
# To verify if the signature is valid
print(Ecdsa.verify(message, signature, publicKey1))