Esempio n. 1
0
    def decode(self, body):
        """
		cipher a json text
		json ojbect have three addt:
		k:encrypted rc4 key
		s:signature
		c:ciphertext encrypted by key
		"""
        d = json.loads(body)
        signature = d['s']
        sk = self.rsa.decode(self.mypri, d['k'])
        # print('sk=',sk,'k=',d['k'],type(d['k']))
        rc4 = RC4(sk)
        t = rc4.decode(d['c'])
        d = json.loads(t)
        ret = d['data']
        if self.peerpub is not None and not self.rsa.check_sign(
                self.peerpub, sk, signature):
            return None
        if self.peerpub is None:
            peerpub = self.getPeerPublicKey(d['id'])
            if peerpub is None:
                return None
            if not self.rsa.check_sign(peerpub, sk, signature):
                return None
        return ret
Esempio n. 2
0
 def __init__(self, myname, privatefile, coding='utf-8'):
     self.rsa = RSA()
     self.rc4 = RC4()
     self.nodes = {}
     self.myname = myname
     self.coding = coding
     self.private_key = self.rsa.read_privatekey(privatefile)
     self.public_key = self.rsa.create_publickey(self.private_key)
Esempio n. 3
0
    def encode(self, text):
        """
		return a json text
		json ojbect have three addt:
		k:encrypted rc4 key
		s:signature
		c:ciphertext encrypted by key
		"""
        d = {"id": self.myid, "data": text}
        text = json.dumps(d)
        sk = self._genSystematicKey()
        rc4 = RC4(sk)
        c = rc4.encode(text)
        s = self.rsa.sign(self.mypri, sk)
        if self.peerpub is None:
            return None
        k = self.rsa.encode(self.peerpub, sk)
        d = {'c': c, 'k': k, 's': s}
        return json.dumps(d)
Esempio n. 4
0
def path_decode(dpath):
    rc4 = RC4()
    return rc4.decode(dpath, crypto_aim)
Esempio n. 5
0
def path_encode(path):
    rc4 = RC4()
    return rc4.encode(path, crypto_aim)
Esempio n. 6
0
	def __init__(self,db,encryptKey):
		super(DatabaseAC,self).__init__()
		self.db = db
		self.pool = DBPools()
		self.encryptKey = encryptKey
		self.rc4 = RC4(encryptKey)
Esempio n. 7
0
		crud = _CRUD(self,db,'ac_rolepermission')
		ns = {
			"rp_id":getID(),
			"role_id":roleid,
			"perm_id":permid
		}
		crud.C(ns)
		return ns
		
if __name__ == '__main__':
	from appPublic.jsonConfig import getConfig
	from sqlor.dbpools import DBPools
	p = 'd:/run'
	conf = getConfig(p)
	DBPools(conf.databases)
	ac = DatabaseAC('metadb',conf.encryptkey)
	#ns1 = ac.addUser('root','根用户','ymq123')
	#ns2 = ac.addRole('superuser')
	#ns3 = ac.addUserRole(ns1['user_id'],ns2['role_id'])
	ups = [
		['root','ymq123'],
		['root','YYYY'],
		['rrrr','ymq123']
	]
	rc4_1 = RC4(conf.encryptkey)
	rc4_2 = RC4(conf.encryptkey)
	for a in ups:
		#print(a[1],rc4_1.encode(a[1])==rc4_2.encode(a[1]))
		print(a[0],a[1],ac.checkPassword(a[0],a[1]))