Example #1
0
def AS_to_Client(ip_Client, r):
    Key_c = (r.get('Key_Client')).decode()
    Key_c = tostr.key_tostr(Key_c)
    QW.Key_client = Key_c

    Key_ctgs = (r.get('Key_ctgs')).decode()  # 理论上从数据库获取
    Key_ctgs = tostr.key_tostr(Key_ctgs)
    print("Key_ctgs = ", Key_ctgs)

    ip_TGS = (r.get('ip_TGS')).decode()  # 从数据库获取TGS的IP地址
    ip_TGS = tostr.ip_tostr(ip_TGS)
    ts2 = time.time()
    ts2 = tostr.ts_tostr(ts2)

    lifetime2 = 666
    lifetime2 = tostr.lifetime_tostr(lifetime2)

    ip_Client = tostr.ip_tostr(ip_Client)

    ticket_tgs = get_ticket(Key_ctgs, ip_Client, ip_TGS, ts2, lifetime2, r)

    message = Key_ctgs + ip_TGS + ts2 + lifetime2 + ticket_tgs
    QW.message2_Plaintext = message
    message = des_en.test(message, Key_c)
    QW.message2_Ciphertext = message
    return message
Example #2
0
def get_ticket(Key_ctgs, ip_Client, ip_TGS, ts2, lifetime2, r):
    # 在此要从数据库获取E_tgs,是TGS和AS之间使用的对称密钥
    Key_tgs = (r.get('Key_TGS')).decode()
    AD_c = ip_Client
    ticket = Key_ctgs + ip_Client + ip_Client + ip_TGS + ts2 + lifetime2
    ticket = des_en.test(ticket, Key_tgs)
    print("ticket = ", ticket)
    return ticket
Example #3
0
def get_ticket(ip_Client, AD_Client, ip_Server, Key_cv, Key_server):
    ts4 = time.time()
    ts4 = tostr.ts_tostr(ts4)

    lifetime4 = 666
    lifetime4 = tostr.lifetime_tostr(lifetime4)

    ticket_Server = Key_cv + ip_Client + AD_Client + ip_Server + ts4 + lifetime4
    ticket_Server = des_en.test(ticket_Server, Key_server)
    print("ticket_server = ", ticket_Server)
    return ticket_Server, ts4
Example #4
0
def get_ticket(Key_ctgs, ip_Client, ip_TGS, ts2, lifetime2, r):
    # 在此要从数据库获取E_tgs,是TGS和AS之间使用的对称密钥
    Key_tgs = (r.get('Key_TGS')).decode()
    QW.Key_tgs = Key_tgs
    AD_c = ip_Client
    ticket = Key_ctgs + ip_Client + ip_Client + ip_TGS + ts2 + lifetime2
    QW.ticket_tgs_Plaintext = ticket
    ticket = des_en.test(ticket, Key_tgs)
    QW.ticket_tgs_Ciphertext = ticket
    print("ticket = ", ticket)
    return ticket
Example #5
0
def get_Authencator(Key_ctgs):
    ip_Client = tostr.get_host_ip()
    ip_Client = tostr.ip_tostr(ip_Client)

    AD_c = ip_Client

    ts3 = time.time()
    ts3 = tostr.ts_tostr(ts3)

    authencator = ip_Client + AD_c + ts3
    authencator = des_en.test(authencator, Key_ctgs)

    return authencator, ts3
Example #6
0
def TGS_to_Client(ip_Client, ip_Server, Key_ctgs):

    Key_server = 'bcdefgh'
    Key_server = tostr.ip_tostr(Key_server)
    Key_cv = get_key()
    Key_server = tostr.ip_tostr(Key_server)

    ip_Server = tostr.ip_tostr(ip_Server)
    ip_Client = tostr.ip_tostr(ip_Client)
    AD_Client = ip_Client
    ticket_Server, ts4 = get_ticket(ip_Client, AD_Client, ip_Server, Key_cv,
                                    Key_server)
    message = Key_cv + ip_Server + ts4 + ticket_Server
    message = des_en.test(message, Key_ctgs)
    print("message = ", message)
    return message
Example #7
0
def TGS_to_Client(ip_Client, ip_Server, Key_ctgs):

    Key_server = 'bcdefgh'
    QW.Key_server = Key_server
    Key_server = tostr.ip_tostr(Key_server)
    Key_cv = get_key()
    Key_server = tostr.ip_tostr(Key_server)

    ip_Server = tostr.ip_tostr(ip_Server)
    ip_Client = tostr.ip_tostr(ip_Client)
    AD_Client = ip_Client
    ticket_Server,ts4 = get_ticket(ip_Client,AD_Client,ip_Server,Key_cv,Key_server)
    message = Key_cv + ip_Server + ts4 + ticket_Server
    QW.message4_Plaintext = message
    message = des_en.test(message, Key_ctgs)
    QW.message4_Ciphertext = message
    print("message = ", message)
    return message
Example #8
0
def Server_to_Client(ts5, Key_cv):
    ts5 += 1
    ts5 = tostr.ts_tostr(ts5)
    message = des_en.test(ts5, Key_cv)
    return message
Example #9
0
    #r = redis.Redis(host='localhost', port=6379, db=0)
    #print(r.get('Key_Client'))
    #As.AS()
    #Tgs.TGS()
    #Server.SERVER()
    #Client.CLIENT()

    #print("输入对称加密密钥:")
    #key1 = input()
    #print("输入要加密的明文:")
    #p = input()
    time1 = time.time()

    key1 = 'ancdefg'
    p = '1994年初秋,天气已经微凉,树叶的颜色早已老成暗淡,天空也老是阴沉沉的,空气中弥漫的令人窒息的静寂。家院子里的木瓜树直挺挺的立在那里,高挑而纤细,头部孤零零的挂着几个还未成熟的果实,也不知是个哪个捣蛋鬼竟拿石头丢的木瓜淌出了汁液,活像人的眼泪。母亲就是在这样的一个季节来到父亲家中的。当时家中有四兄弟父亲排行老四,一家人黑压压全部挤在这个用黄土堆砌成的小院子里,父亲的住处是用木板围成的不足20平米的小房间,母亲心里想着这么小的屋子放张床和衣柜人倒是就走不进去了,这陈旧的瓦房雨天估计还会漏雨。母亲心里本来就憋屈难受,哪知第二天大清早的,还未过门的三伯母娘家人听闻母亲的到来怒气冲冲的跑来告诫父亲,不允许父亲在三伯父之前成婚。母亲气坏了哪有人这么蛮横的,顺着这股气母亲干脆就走了。'
    ciphertext = en.test(p, key1)
    print("ciphertext = ", ciphertext)

    plaintext = de.test(ciphertext, key1)
    print("plaintext = ", plaintext)

    e, d, n = rsa.get_key()  # 非对称加密的密钥获取,或者自己设定也行

    ciphertext1 = rsa.encryption(p, e, n)
    print("rsa ciphertext = ", ciphertext1)
    plaintext1 = rsa.decryption(ciphertext1, d, n)
    print("rsa plaintext = ", plaintext1)

    time2 = time.time()
    print("time = ", 1000 * (time2 - time1), "ms")