예제 #1
0
import DarkCloudCryptoLib as dcCryptoLib
from Crypto.PublicKey import RSA
import os

# ##test Equal RSA keys
rsaKey1 = dcCryptoLib.makeRSAKeyObj("password", "username")
rsaKey2 = dcCryptoLib.makeRSAKeyObj("password", "username")
print "equal RSA keys: ", dcCryptoLib.equalRSAKeys(rsaKey1, rsaKey2)

##test lock and unlock functions work
tableKey = dcCryptoLib.DCTableKey('password', 'username', 'keyFilename')
tableKeyCopy = dcCryptoLib.DCCryptoClient().createUserMasterKeyObj('password', 'username', 'keyFilename')
print "test: ",tableKey == tableKeyCopy

plaintext = "brando"

secureData = tableKey.lock(plaintext)
decryptedData = tableKey.unlock(secureData)
print "test1: ", decryptedData == plaintext
secureData = tableKey.lock(plaintext)
decryptedData2 = tableKey.unlock(secureData)
print "test2: ", decryptedData2 == plaintext
secureData = tableKey.lock(plaintext)
decryptedData3 = tableKey.unlock(secureData)
print "test3: ", decryptedData3 == plaintext

dcSignature = tableKey.dcSign(plaintext)
unSigned = tableKey.dcVerify(dcSignature)
print "test4: ", unSigned == plaintext

ciphertext = tableKey.dcEncrypt(plaintext)
예제 #2
0
from Crypto.Protocol.KDF import PBKDF2
from Crypto.PublicKey import RSA
import DarkCloudCryptoLib as dcCryptoLib

password = "******"   # for testing
salt = "yourAppName"     # replace with random salt if you can store one

master_key = PBKDF2(password, salt, count=10000)  # bigger count = better

def my_rand(n):
    # PBKDF2 with count=1 and a variable salt makes a handy key-expander
    my_rand.counter += 1
    #return PBKDF2(master_key, salt, dkLen=n, count=1)
    return PBKDF2(master_key, "my_rand:%d" % my_rand.counter, dkLen=n, count=1)

my_rand.counter = 0
RSA_key1 = RSA.generate(2048, randfunc=my_rand)
my_rand.counter = 0
RSA_key2 = RSA.generate(2048, randfunc=my_rand)
print dcCryptoLib.equalRSAKeys(RSA_key1, RSA_key2)
예제 #3
0
import DarkCloudCryptoLib as dcCryptoLib
from Crypto.PublicKey import RSA
import os

# ##test Equal RSA keys
rsaKey1 = dcCryptoLib.makeRSAKeyObj("password", "username")
rsaKey2 = dcCryptoLib.makeRSAKeyObj("password", "username")
print "equal RSA keys: ", dcCryptoLib.equalRSAKeys(rsaKey1, rsaKey2)

##test lock and unlock functions work
tableKey = dcCryptoLib.DCTableKey('password', 'username', 'keyFilename')
tableKeyCopy = dcCryptoLib.DCCryptoClient().createUserMasterKeyObj(
    'password', 'username', 'keyFilename')
print "test: ", tableKey == tableKeyCopy

plaintext = "brando"

secureData = tableKey.lock(plaintext)
decryptedData = tableKey.unlock(secureData)
print "test1: ", decryptedData == plaintext
secureData = tableKey.lock(plaintext)
decryptedData2 = tableKey.unlock(secureData)
print "test2: ", decryptedData2 == plaintext
secureData = tableKey.lock(plaintext)
decryptedData3 = tableKey.unlock(secureData)
print "test3: ", decryptedData3 == plaintext

dcSignature = tableKey.dcSign(plaintext)
unSigned = tableKey.dcVerify(dcSignature)
print "test4: ", unSigned == plaintext
예제 #4
0
                      "my_rand:%d" % my_rand.counter,
                      dkLen=n,
                      count=1)

    my_rand.counter = 0
    RSA_key = RSA.generate(2048, randfunc=my_rand)
    return RSA_key


password = "******"  # for testing
salt = "yourAppName"  # replace with random salt if you can store one

key1 = makeRSAkey(password, salt)
key2 = makeRSAkey(password, salt)

print "keys eqyal: ", dcCryptoLib.equalRSAKeys(key1, key2)

#public_key = self.rsaKeyObj.publickey()
#self.rsaKeyObj.sign(hashVal, '')

#key = key1.exportKey('PEM')
keyPubStr = key1.publickey().exportKey('PEM')
print type(keyPubStr)
keyPub = RSA.importKey(keyPubStr)
#newKey1 = RSA.importKey(key)
print "can keyPub encrypt, ", keyPub.can_encrypt()
print "can keyPub sign, ", keyPub.can_sign()
print "can keyPub has_private, ", keyPub.has_private()
print keyPub.sign("", '')
# print "keys equal: ", key1.publickey() == newKey1 and key2.publickey() == newKey1
# strKey = newKey1.exportKey('PEM')
예제 #5
0
    	# PBKDF2 with count=1 and a variable salt makes a handy key-expander
    	my_rand.counter += 1
    	#return PBKDF2(master_key, salt, dkLen=n, count=1)
    	return PBKDF2(master_key, "my_rand:%d" % my_rand.counter, dkLen=n, count=1)
    my_rand.counter = 0
    RSA_key = RSA.generate(2048, randfunc=my_rand)
    return RSA_key


password = "******"   # for testing
salt = "yourAppName"     # replace with random salt if you can store one

key1 = makeRSAkey(password, salt)
key2 = makeRSAkey(password, salt)

print "keys eqyal: ", dcCryptoLib.equalRSAKeys(key1, key2)

#public_key = self.rsaKeyObj.publickey()
#self.rsaKeyObj.sign(hashVal, '')

#key = key1.exportKey('PEM')
keyPubStr = key1.publickey().exportKey('PEM')
print type(keyPubStr)
keyPub = RSA.importKey(keyPubStr)
#newKey1 = RSA.importKey(key)
print "can keyPub encrypt, ", keyPub.can_encrypt()
print "can keyPub sign, ", keyPub.can_sign()
print "can keyPub has_private, ", keyPub.has_private()
print keyPub.sign("",'')
# print "keys equal: ", key1.publickey() == newKey1 and key2.publickey() == newKey1
# strKey = newKey1.exportKey('PEM')
예제 #6
0
from Crypto.PublicKey import RSA
from Crypto import Random
import DarkCloudCryptoLib as dcCryptoLib

import hashlib
import sys
import os

#comparing RSA keys
# random_generator = Random.new().read
# new_key = RSA.generate(1024, random_generator) #rsaObj 
# public_key = new_key.publickey().exportKey("DER") 
# private_key = new_key.exportKey("DER") 

# pub_new_key = RSA.importKey(public_key)
# pri_new_key = RSA.importKey(private_key)
# pub_new_key = pub_new_key.exportKey("DER")
# pri_new_key = pri_new_key.exportKey("DER")
# print private_key == pri_new_key , public_key == pub_new_key
password = "******"

new_key1 = RSA.generate(1024, lambda n: (chr(0)*(n-1))+chr(1) ) #rsaObj
exportedKey1 = new_key1.exportKey('DER', password, pkcs=1)
key1 = RSA.importKey(exportedKey1)

new_key2 = RSA.generate(1024, lambda n: (chr(0)*(n-1))+chr(1) ) #rsaObj
exportedKey2 = new_key2.exportKey('DER', password, pkcs=1)
key2 = RSA.importKey(exportedKey2)
print dcCryptoLib.equalRSAKeys(key1, key2)
예제 #7
0
from Crypto.Protocol.KDF import PBKDF2
from Crypto.PublicKey import RSA
import DarkCloudCryptoLib as dcCryptoLib

password = "******"  # for testing
salt = "yourAppName"  # replace with random salt if you can store one

master_key = PBKDF2(password, salt, count=10000)  # bigger count = better


def my_rand(n):
    # PBKDF2 with count=1 and a variable salt makes a handy key-expander
    my_rand.counter += 1
    #return PBKDF2(master_key, salt, dkLen=n, count=1)
    return PBKDF2(master_key, "my_rand:%d" % my_rand.counter, dkLen=n, count=1)


my_rand.counter = 0
RSA_key1 = RSA.generate(2048, randfunc=my_rand)
my_rand.counter = 0
RSA_key2 = RSA.generate(2048, randfunc=my_rand)
print dcCryptoLib.equalRSAKeys(RSA_key1, RSA_key2)