Exemple #1
0
 def test_sign_and_verify(self):
     msg = b'This message will be signed\n'
     pw = b'my private key'
     for c in seccure.curves:
         pubkey = str(seccure.passphrase_to_pubkey(pw, curve=c))
         self.assertTrue(seccure.verify(msg, seccure.sign(msg, pw, curve=c),
                                        pubkey, curve=c))
Exemple #2
0
 def test_sign_and_verify(self):
     msg = b'This message will be signed\n'
     pw = b'my private key'
     for c in seccure.curves:
         pubkey = str(seccure.passphrase_to_pubkey(pw, curve=c))
         self.assertTrue(seccure.verify(msg, seccure.sign(msg, pw, curve=c),
                                        pubkey, curve=c))
Exemple #3
0
def verify(message, signature, public_key):
    msg_bytes = utf8_encode(message)
    sign_bytes = hex_decode(signature)
    pubkey_bytes = hex_decode(public_key)
    return seccure.verify(msg_bytes,
                          sign_bytes,
                          pubkey_bytes,
                          curve=default_curve_name,
                          sig_format=seccure.SER_BINARY,
                          pk_format=seccure.SER_BINARY)
Exemple #4
0
    def verify(self, message, signature, public_key):
        """Verifies a signature.
           
           @param message The message that was signed.
           @param signature The signature.
           @param public_key The key to use to verify the signature.
        """

        authentic = seccure.verify(message, signature, public_key)
        self.logger.debug("Verified " + str(len(message)) + " bytes against key '" + public_key.decode("utf-8") + "', authentic = " + str(authentic))
        return authentic
Exemple #5
0
    def valid(self):
        """Check if this object is valid or not"""
        if not self.signature or self.signature.find(' ') < 0:
            return False

        public_key = self.signature.split(' ')[1]
        valid = True

        valid = valid and seccure.verify(
            self.serialize(include_signature=False),
            self.signature.split(' ')[0],
            public_key,
        )
        valid = valid and (self.user == get_address(
            public_key.encode('utf-8')))

        valid = valid and (self.id == self.hash)

        return valid
Exemple #6
0
 def test_verify(self):
     msg = b'This message will be signed\n'
     sig = b'$HPI?t(I*1vAYsl$|%21WXND=6Br*[>k(OR9B!GOwHqL0s+3Uq'
     pubkey = '8W;>i^H0qi|J&$coR5MFpR*Vn'
     self.assertTrue(seccure.verify(msg, sig, pubkey))
Exemple #7
0
 def test_forwards_compatibility_issue_16(self):
     msg = b'ttrMWDqBxjC8UAl8X4TRDSSpd1IyYMh4\n'
     sig = b'!!!5{LV[=|t~46wS2y<Ub9Ol;uO/fPGU*JYKid+|(JBMspwk7S'
     pw = b'my private key'
     pubkey = str(seccure.passphrase_to_pubkey(pw))
     self.assertTrue(seccure.verify(msg, sig, pubkey))
Exemple #8
0
def verify_signature(m, signature, pub_key):
    return seccure.verify(m, signature, pub_key, curve="brainpoolp384r1")
Exemple #9
0
    #build the key for hmac using scrypt
    skey = scrypt.hash('password_goes_here', hashlib.sha256(secret).hexdigest())[:32]
    #skey = scrypt.encrypt('password', secret,  maxtime=0.5)
    print ('SCRYPT: \t{}'.format(hex(bytes_to_long(skey))))

    #XOR the scrypt key with the secret to create the hmac key
    hashkey = bytes_to_long(secret) ^ bytes_to_long(skey)
    print ('HASHKEY: \t{}'.format(hex(hashkey)))

    #build the hmac hash from the msg using sha256
    hmac = HMAC.new(long_to_bytes(hashkey), msg='foo'.encode(), digestmod=SHA256.new())
    hash = hmac.hexdigest()
    print ('HMAC: \t\t{}'.format(hash))

    #create the ECC private key from the hmac hash
    newprv = hash.encode()
    newpub = str(seccure.passphrase_to_pubkey(newprv))
    print ('ECC PRIVATE: \t{}'.format(newprv))
    print ('ECC PUBLIC:  \t{}'.format(newpub))

    #sign the message
    sig = seccure.sign('bar'.encode(), newprv)
    print ('ECC SIG: \t{}'.format(sig))

    #attempt verification
    if seccure.verify('bar'.encode(), sig, newpub):
        print('GOOD SIGNATURE')
    else    :
        print('BAD SIGNATURE')
Exemple #10
0
 def test_verify(self):
     msg = b'This message will be signed\n'
     sig = b'$HPI?t(I*1vAYsl$|%21WXND=6Br*[>k(OR9B!GOwHqL0s+3Uq'
     pubkey = '8W;>i^H0qi|J&$coR5MFpR*Vn'
     self.assertTrue(seccure.verify(msg, sig, pubkey))
Exemple #11
0
 def test_forwards_compatibility_issue_16(self):
     msg = b'ttrMWDqBxjC8UAl8X4TRDSSpd1IyYMh4\n'
     sig = b'!!!5{LV[=|t~46wS2y<Ub9Ol;uO/fPGU*JYKid+|(JBMspwk7S'
     pw = b'my private key'
     pubkey = str(seccure.passphrase_to_pubkey(pw))
     self.assertTrue(seccure.verify(msg, sig, pubkey))
Exemple #12
0
def verify_signature(m, signature, pub_key):
    return seccure.verify(m, signature, pub_key, curve="brainpoolp384r1")
#
#
# using elliptic curve cryptography to encrypt messages. 
#
# use with seccure: https://github.com/MeeSeongIm/py-seccure
#
#



import seccure

str(seccure.passphrase_to_pubkey(b'my private key'))  # devive the public key 

ciphertext = seccure.encrypt(b'This is a secret message.\n', b'8W;>i^H0qi|J&$coR5MFpR*Vn')

print(ciphertext)

seccure.decrypt(ciphertext, b'my private key')

seccure.sign(b'This will be a signed message.\n', b'my private key') 

seccure.verify(b'This will be a signed message.\n', b'', b'8W;>i^H0qi|J&$coR5MFpR*Vn')  # to verify the signature

 def verify(message, signature, key):
     args = (message, signature, key)
     if not args in Public.cache:
         result = seccure.verify(message, signature, key)
         Public.cache[args] = result
     return Public.cache[args]
Exemple #15
0
                       hashlib.sha256(secret).hexdigest())[:32]
    #skey = scrypt.encrypt('password', secret,  maxtime=0.5)
    print('SCRYPT: \t{}'.format(hex(bytes_to_long(skey))))

    #XOR the scrypt key with the secret to create the hmac key
    hashkey = bytes_to_long(secret) ^ bytes_to_long(skey)
    print('HASHKEY: \t{}'.format(hex(hashkey)))

    #build the hmac hash from the msg using sha256
    hmac = HMAC.new(long_to_bytes(hashkey),
                    msg='foo'.encode(),
                    digestmod=SHA256.new())
    hash = hmac.hexdigest()
    print('HMAC: \t\t{}'.format(hash))

    #create the ECC private key from the hmac hash
    newprv = hash.encode()
    newpub = str(seccure.passphrase_to_pubkey(newprv))
    print('ECC PRIVATE: \t{}'.format(newprv))
    print('ECC PUBLIC:  \t{}'.format(newpub))

    #sign the message
    sig = seccure.sign('bar'.encode(), newprv)
    print('ECC SIG: \t{}'.format(sig))

    #attempt verification
    if seccure.verify('bar'.encode(), sig, newpub):
        print('GOOD SIGNATURE')
    else:
        print('BAD SIGNATURE')