Ejemplo n.º 1
0
def verSign(kFilename1, kFilename2, mFilename, sFilename, wFilename):
    with open(kFilename1) as f:
        key = f.read()
        rsakey = RSA.importKey(key)
        verifier = Signature_pkcs1_v1_5.new(rsakey)
        digest = SHA1.new()
    with open(mFilename, 'r') as f1:
        message = f1.read()
    with open(sFilename, 'r') as f2:
        message = message + f2.read()
        digest.update(message.encode('utf8'))

    signature = DES.decryptDes(wFilename, kFilename2, wFilename)
    signature = base64.b64decode(signature)

    is_verify = verifier.verify(digest, signature)
    return is_verify
Ejemplo n.º 2
0
                 './receiver_file/receive_des_key.txt',
                 './receiver_file/receive_sign.txt')
receiver.shutdown()
print()
print("数据接收完成")
print("断开连接")
print()

decryptDESKey = RSA.decryptRSA('./receiver_file/rsa_des_private.txt',
                               './receiver_file/receive_des_key.txt')
with open('./receiver_file/decrypt_des_key.txt', 'w') as f:
    f.write(decryptDESKey.decode('utf8'))
print("des密钥解密完成")

DES.decryptDes('./receiver_file/receive_message.txt',
               './receiver_file/decrypt_des_key.txt',
               './receiver_file/decrypt_message.txt')
print("接收消息des解密完成")

with open('./receiver_file/decrypt_message.txt', 'r') as f:
    message = f.read()
    print("解密后的消息: " + message)
    print()

flag = RSA.verSign('./publickey_file/rsa_sign_public.txt',
                   './receiver_file/decrypt_des_key.txt',
                   './receiver_file/decrypt_message.txt',
                   './receiver_file/sha1_s.txt',
                   './receiver_file/receive_sign.txt')

if (flag is True):