Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 3
0
def sign(message, passphrase):
    passphrase_bytes = utf8_encode(passphrase)

    msg_bytes = utf8_encode(message)
    non_hex_sig = seccure.sign(msg_bytes,
                               passphrase_bytes,
                               sig_format=seccure.SER_BINARY)
    return hex_encode(non_hex_sig)
Ejemplo n.º 4
0
 def sign(self, move: Move):
     """ put signature into the given move using the user's private key. """
     if move.name is None:
         raise InvalidNameError
     move.user = self.address
     serialized = move.serialize(include_signature=False)
     move.signature = '{signature} {public_key}'.format(
         signature=seccure.sign(
             serialized, self.private_key.encode('utf-8')).decode('utf-8'),
         public_key=self.public_key,
     )
     move.id = move.hash
Ejemplo n.º 5
0
    def sign(self, message, private_key):
        """Signs a message with a private_key.

           @param message The message to sign.
           @param private_key The private key to use for signing.
           @return A signature which can be verified with the public key
                   that pairs with @private_key.
        """
        # sign:
        signature = seccure.sign(message, private_key).decode('utf-8')
        self.logger.debug("Signed " + str(len(message)) + " bytes with private key")
        return signature
Ejemplo n.º 6
0
 def test_sign_length(self):
     msg = b'ttrMWDqBxjC8UAl8X4TRDSSpd1IyYMh4\n'
     pw = b'my private key'
     self.assertEqual(seccure.sign(msg, pw),
                      b'!!!5{LV[=|t~46wS2y<Ub9Ol;uO/fPGU*JYKid+|(JBMspwk7S')
Ejemplo n.º 7
0
 def test_sign(self):
     msg = b'This message will be signed\n'
     pw = b'my private key'
     self.assertEqual(seccure.sign(msg, pw),
                      b'$HPI?t(I*1vAYsl$|%21WXND=6Br*[>k(OR9B!GOwHqL0s+3Uq')
Ejemplo n.º 8
0
def sign_with_pass_phrase(m, pass_phrase):
    return seccure.sign(m, pass_phrase, curve="brainpoolp384r1")
Ejemplo n.º 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')
Ejemplo n.º 10
0
 def test_sign_length(self):
     msg = b'ttrMWDqBxjC8UAl8X4TRDSSpd1IyYMh4\n'
     pw = b'my private key'
     self.assertEqual(seccure.sign(msg, pw),
                      b'!!!5{LV[=|t~46wS2y<Ub9Ol;uO/fPGU*JYKid+|(JBMspwk7S')
Ejemplo n.º 11
0
 def test_sign(self):
     msg = b'This message will be signed\n'
     pw = b'my private key'
     self.assertEqual(seccure.sign(msg, pw),
                      b'$HPI?t(I*1vAYsl$|%21WXND=6Br*[>k(OR9B!GOwHqL0s+3Uq')
Ejemplo n.º 12
0
def sign_with_pass_phrase(m, pass_phrase):
    return seccure.sign(m, pass_phrase, 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

Ejemplo n.º 14
0
 def sign(message, key):
     return seccure.sign(message, key, seccure.SER_COMPACT,
                         "secp256r1/nistp256")
Ejemplo n.º 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')