如何加密.bin文件

时间:2015-12-21 15:52:32

标签: python encryption

我需要加密包含2个Diffie-Hellman密钥的3个.bin个文件。我不知道如何做到这一点,我能想到的就是我在下面的Python文件中所做的。我有一个示例输出应该是什么样子但我的代码似乎没有产生正确的键。客户端使用输出文件server.ini连接到服务器。

import base64

fileList = [['game_key.bin', 'Game'], ['gate_key.bin', 'Gate'], ['auth_key.bin', 'Auth']]
iniList = []
for i in fileList:
    file = open(i[0], 'rb')
    n = list(file.read(64))
    x = list(file.read(64))
    file.close()
    n.reverse()
    x.reverse()
    iniList.append(['Server.' + i[1] + '.N "' + base64.b64encode("".join(n)) + '"\n', 'Server.' + i[1] + '.X "' + base64.b64encode("".join(x)) + '"\n'])
iniList[0].append('\n')

#time for user Input

ip = '"' + raw_input('Hostname: ') + '"'
dispName = 'Server.DispName ' + '"' + raw_input('DispName: ') + '"' + '\n'
statusUrl = 'Server.Status ' + '"' + raw_input('Status URL: ') + '"' + '\n'
signupUrl = 'Server.Signup ' + '"' + raw_input('Signup URL: ') + '"' + '\n'

for l in range(1, 3):
    iniList[l].append('Server.' + fileList[l][1] + '.Host ' + ip + '\n\n')

for l in [[dispName], [statusUrl], [signupUrl]]:
    iniList.append(l)

outFile = open('server.ini', 'w')

for l in iniList:
    for i in l:
        outFile.write(i)

outFile.close()

以下是我的示例文件:

# Keys are Base64-encoded 512 bit RC4 keys, as generated by DirtSand's keygen
# command.  Note that they MUST be quoted in the commands below, or the client
# won't parse them correctly!

我也在不反转nx

的情况下尝试了它

0 个答案:

没有答案