示例#1
0
 def test_passphrase_to_pubkey(self):
     self.assertEqual(str(seccure.passphrase_to_pubkey(b'test')),
                             '*jMVCU^[QC&q*v_8C1ZAFBAgD')
     self.assertEqual(str(seccure.passphrase_to_pubkey(b'my private key')),
                             '8W;>i^H0qi|J&$coR5MFpR*Vn')
     self.assertRaises(ValueError, seccure.passphrase_to_pubkey,
                         six.u('test'))
示例#2
0
 def test_encrypt(self):
     msg = b'My private message'
     pw = b'my private key'
     pk = str(seccure.passphrase_to_pubkey(pw))
     self.assertEqual(seccure.decrypt(seccure.encrypt(msg, pk), pw), msg)
     for c in seccure.curves:
         self.assertEqual(
             seccure.decrypt(
                 seccure.encrypt(
                     msg,
                     str(seccure.passphrase_to_pubkey(pw, curve=c)),
                     curve=c),
                 pw, curve=c),
             msg)
示例#3
0
 def test_encrypt(self):
     msg = b'My private message'
     pw = b'my private key'
     self.assertEqual(
         seccure.decrypt(
             seccure.encrypt(msg, str(seccure.passphrase_to_pubkey(pw))),
             b'my private key'), msg)
示例#4
0
def create_key():
    # Get the latest id
    latestPKs = models.PrivateKey.query.all()
    priv_id = -1
    for priv in reversed(latestPKs):
        priv_id = priv.id + 1
        break
    if(priv_id == -1):
        priv_id = 1
    # Create private key
    randomStr = os.urandom(64)
    h = hashlib.sha256()
    h.update(randomStr)
    privKey = h.hexdigest()
    publicKey = seccure.passphrase_to_pubkey(privKey)
    # Save private key
    pk = models.PrivateKey(
        name = 'SKYLOCK-' + str(priv_id),
        key = str(privKey))
    db.session.add(pk)
    db.session.commit()
    # Save public key
    pubk = models.PublicKey(
        id = priv_id,
        name = 'SKYLOCK-' + str(priv_id),
        key = str(publicKey)
    )
    db.session.add(pubk)
    db.session.commit()
    # Display new public key
    pubKeyRes = models.PublicKey.query.get(priv_id)
    return jsonify(Public_key=[pubKeyRes.serialize])
示例#5
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))
示例#6
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))
示例#7
0
 def test_generate_keypair(self):
     for curvename in seccure.curves:
         privkey, pubkey = seccure.generate_keypair(curve=curvename)
         self.assertEqual(
             str(seccure.passphrase_to_pubkey(
                 privkey,
                 curve=curvename,
             )), pubkey)
示例#8
0
 def accepted(self):
     self.conn = sqlite3.connect("Data.db")
     self.c = self.conn.cursor()
     # key = convertpass(self.passStringAdd)
     # iv = Random.new().read(DES3.block_size)
     # cipher_encrypt = DES3.new(key, DES3.MODE_OFB, iv)
     # passwordpadded = convertToMUL8(self.Password.text())
     private_key = self.passStringAdd
     public_key = str(seccure.passphrase_to_pubkey(private_key.encode()))
     self.c.execute("INSERT INTO PASSES VALUES(?, ?, ?, ?)", [(self.id), (self.Company.text()), (self.Username.text()), (seccure.encrypt(self.Password.text().encode(), public_key.encode()))])
     print("A New Password FIELD ADDED.")
     self.conn.commit()
     self.accept()
示例#9
0
文件: app.py 项目: Anuraj99/Cyber
 def on_click_submit(self):
     self.conn = sqlite3.connect("BankDB.db")
     self.c = self.conn.cursor()
     self.h = hashlib.sha512()
     self.h.update(self.PasswordField.text().encode())
     self.hash = self.h.digest()
     self.publicKey = str(seccure.passphrase_to_pubkey(b'my private key'))
     self.date = datetime.datetime.now()
     self.c.execute("INSERT INTO USERS(NAME, USERNAME, PASSWORD, ACCOUNT_ID, PubKey) VALUES(?, ?, ?, ?, ?);", [(self.NameField.text()), (self.User_NameField.text()), (self.hash), (self.Account_NumberField.text()), (self.publicKey)])
     self.c.execute('INSERT INTO SAMPE VALUES(00001, 00001, ?, ?, ?, ?, ?)', [(self.Account_NumberField.text()), (seccure.encrypt(self.NetBalance.text().encode(), b'8W;>i^H0qi|J&$coR5MFpR*Vn')), (str(self.date.time())), (str(self.date.date())), (hashTransaction(self.date.time(), self.Account_NumberField.text()))])
     self.conn.commit()
     self.conn.close()
     self.close()
示例#10
0
 def on_click_send(self):
     self.conn = sqlite3.connect('BankDB.db')
     self.c = self.conn.cursor()
     self.date = datetime.datetime.now()
     self.id = s.encrypt(
         self.hashTransaction(self.date.time(), self.accID).encode(),
         str(s.passphrase_to_pubkey(b'my private key')))
     self.amt = s.encrypt(self.Amount.text().encode(),
                          str(s.passphrase_to_pubkey(b'my private key')))
     print("Transaction ID : " + str(self.id))
     print("\nAmount sent : " + str(self.amt))
     self.c.execute('INSERT INTO SAMPE VALUES(?, ?, ?, ?, ?, ?, ?);',
                    [(self.accID), (self.accID),
                     (self.ReceiversID.text()), self.amt,
                     (str(self.date.time())),
                     (str(self.date.date())), self.id])
     print("\nSuccessfully Transferred")
     # self.fetchdata = self.c.execute('SELECT NETBALANCE FROM USERS where ACCOUNT_ID = ?', [(self.accID)])
     # for i in self.fetchdata:
     # self.intbalnow = i[0]
     # self.c.execute('UPDATE USERS SET NETBALANCE = ? WHERE ACCOUNT_ID =?',[(self.intbalnow - int(self.Amount.text())), (self.accID)])
     self.conn.commit()
     self.close()
示例#11
0
    def __init__(self, _private_key=None, _public_key=None):
        """Generates a new keypair. This object can be serialized to store the pair generated.
        
           To generate a NEW key, set both parameters to None (simply invoke the constructor
           w/o arguments). To load/use an existing pair pass them as parameter. You can not
           use this object to store ONLY a private or public key.

           You may read out the 'private_key' and 'public_key' properties directly.

           @param _private_key An existing private key (or None). Should be in base64 format.
           @param _public_key An existing public key (or None). Should be in base64 format.
        """

        assert (_private_key is None and _public_key is None) or (_private_key is not None and _public_key is not None)

        if _private_key is None:
            # Although the private key could be (a lot) shorter, I am sticking to a
            # private key with the byte length the same as the bit length of the curve for now.
            # This won't be easy to guess ...
            self._private_key = Key(''.join(random.choice(string.digits + string.ascii_letters + string.punctuation) for x in range(521)).encode("utf-8"), True)
            self._public_key = Key(str(seccure.passphrase_to_pubkey(self.raw_private_key)).encode("utf-8"), True)
        else:
            self._private_key = Key(_private_key)
            self._public_key = Key(_public_key)
示例#12
0
 def test_issue5(self):
     self.assertEqual(repr(seccure.passphrase_to_pubkey(b'my private key')),
                      '<PubKey 8W;>i^H0qi|J&$coR5MFpR*Vn>')
示例#13
0
 def generate(self, passphrase):
     self._eprv = passphrase.encode()
     self._epub = str(seccure.passphrase_to_pubkey(self._eprv)).encode()
示例#14
0
def generatePublicKey():
    private_Key = 'prueba1'
    public_key = seccure.passphrase_to_pubkey(private_Key.encode())
    print(public_key)
    return public_key
示例#15
0
文件: sqrler.py 项目: xevrem/csdm
    #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')
示例#16
0
 def test_encrypt(self):
     msg = b'My private message'
     pw = b'my private key'
     self.assertEqual(seccure.decrypt(seccure.encrypt(msg,
                     str(seccure.passphrase_to_pubkey(pw))),
                         b'my private key'), msg)
示例#17
0
def get_pub_key(pass_phrase):
    return str(seccure.passphrase_to_pubkey(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

示例#19
0
r = []

for x in range(7):
    packet.append(byteString[(x * N):((N * (x + 1)))])
    #print packet[x]
# Step 2
for y in range(7):
    #r.append(random.choice(enc_list))
    packet[y] = packet[y] + enc_list[y]
    #enc_list.remove(r[y])
    #packet[y] = packet[y] + r[y]
    #print packet[y]
private_key = '77'  #random.choice(string.digits)
#print private_key

public_key = str(seccure.passphrase_to_pubkey(private_key))
ciphertext = []
###Encryption phase
for z in range(7):
    t1 = time.time()
    ct = seccure.encrypt(packet[z][:-3], public_key)
    #print tt
    ciphertext.append(ct)
    t2 = time.time()
    conv = {'ciphertext': ct, 'cloudNo': packet[z][-3:]}
    s = json.dumps(conv, ensure_ascii=False)
    res = requests.post("http://127.0.0.1:5000/determine_escalation/",
                        data=ct + packet[z][-3:]).json()
    print res
    encTime = encTime + (t2 - t1)
    #print ciphertext[z]
示例#20
0
 def publickey(private):
     if private not in Private.pubkey_cache:
         public = seccure.passphrase_to_pubkey(
             private, "secp256r1/nistp256").to_bytes(seccure.SER_COMPACT)
         Private.pubkey_cache[private] = public
     return Private.pubkey_cache[private]
示例#21
0
  def gen_public_key(self):
    if not self.private_key:
      raise ValueError("no private key")

    self.public_key = seccure.passphrase_to_pubkey(self.private_key, curve='secp256r1/nistp256').to_bytes()
    return self.public_key
示例#22
0
def create_pubkey(passphrase):
    passphrase_bytes = utf8_encode(passphrase)
    pubkey_obj = seccure.passphrase_to_pubkey(passphrase_bytes,
                                              curve=default_curve_name)
    return hex_encode(pubkey_obj)
示例#23
0
 def test_issue5(self):
     self.assertEqual(repr(seccure.passphrase_to_pubkey(b"my private key")), "<PubKey 8W;>i^H0qi|J&$coR5MFpR*Vn>")
示例#24
0
文件: eccpgp.py 项目: xevrem/csdm
 def generate(self, passphrase):
     self._eprv = passphrase.encode()
     self._epub = str(seccure.passphrase_to_pubkey(self._eprv)).encode()
示例#25
0
def get_pub_key(pass_phrase):
    return str(
        seccure.passphrase_to_pubkey(pass_phrase, curve="brainpoolp384r1"))
示例#26
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))
示例#27
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))
示例#28
0
 def test_generate_keypair(self):
     for curvename in seccure.curves:
         privkey, pubkey = seccure.generate_keypair(curve=curvename)
         self.assertEqual(
             str(seccure.passphrase_to_pubkey(privkey)), pubkey)
示例#29
0
文件: models.py 项目: dahlia/nekoyume
 def __init__(self, private_key, session=db.session):
     self.private_key = private_key
     self.public_key = str(
         seccure.passphrase_to_pubkey(self.private_key.encode('utf-8')))
     self.session = session
示例#30
0
文件: sqrler.py 项目: xevrem/csdm
                       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')