def add_user_token_table_dic(self, user_id): token = OHHORandom.get_nonce() token_dict = dict() token_dict["user_id"] = user_id token_dict["token"] = token # self.token.token.add(token_dict) return token_dict
def add(self, user_id): token = OHHORandom.get_nonce() token_dict = dict() token_dict["user_id"] = user_id token_dict["token"] = token token_add = self.token.add(token_dict) if token_add: return self.token.get_by_user_id(user_id) else: return None
def get_header(): header = dict() nonce = OHHORandom.get_nonce() current_time = str(OHHODatetime.get_current_timestamp_second()) app_secret = APP_SECRET app_key = APP_KEY check_sum = Header.get_check_sum(app_secret, nonce, current_time) header[HEADER_NAME_NONCE] = nonce header[HEADER_NAME_CURRENT_TIME] = current_time header[HEADER_NAME_APP_KEY] = app_key header[HEADER_NAME_CHECK_SUM] = check_sum return header
text = text + (b'\0' * add) self.ciphertext = cryptor.encrypt(text) # 因为AES加密时候得到的字符串不一定是ascii字符集的,输出到终端或者保存时候可能存在问题 # 所以这里统一把加密后的字符串转化为16进制字符串 # 以unicode存储文件信息 return OHHOOperation.to_str(b2a_hex(self.ciphertext)) # 解密后,去掉补足的空格用strip() 去掉 def decrypt(self, text): cryptor = AES.new(self.key, self.mode, self.key) # 解密文本必须是必须是bytes(utf8或ascii),而不能是unicode(str) utf8_text = OHHOOperation.to_bytes(text) plain_text = cryptor.decrypt(a2b_hex(utf8_text)) return OHHOOperation.to_str(plain_text.rstrip(b'\0')) if __name__ == '__main__': pc = OHHOEncryption(OHHOOperation.to_bytes('keyskeyskeyskeys')) # 初始化密钥 e = pc.encrypt("00000") print(len(e)) d = pc.decrypt(e) print(d) from Tools.ohho_random import OHHORandom test = OHHORandom.get_nonce(15) test_password = OHHOEncryption(OHHOOperation.to_str("ztr7vnwg4jiaeqh8")) print(test_password.encrypt(test)) b = "e332f36055acd3e0272ab1b5a58b14fb" print(len(b))
def get_by_new_imei(self): random = OHHORandom.get_nonce(15) encryption_random = self.encryption.encrypt(random) instance, ex = self.imei.get_by_imei(random) return encryption_random, instance, ex, random
def create_code(length=4): code = OHHORandom.get_numbers(length) while code.startswith('0'): code = OHHORandom.get_numbers(length) return code
def get_imei(): random_imei = OHHORandom.get_nonce(15) return random_imei