我使用此代码加密 plist 文件,但我发现无论密钥是什么,通过 AES 的值都不会改变,有人可以帮我吗?
import hashlib
import os
import subprocess
from M2Crypto import EVP
proj_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))
def encrypt_plist(source_dir, name):
source_file = os.path.join(source_dir, name+'.plist')
target_file = os.path.join(source_dir, name)
hash_file = os.path.join(source_dir, name+'.md5')
tmp_file = os.path.join('/tmp', name+'.plist')
assert os.path.isfile(source_file)
assert not os.path.isfile(tmp_file), 'Cannot create %s which should be removed first' % tmp_file
subprocess.check_call(["cp", source_file, tmp_file])
subprocess.check_call(["plutil", '-convert', 'binary1', tmp_file])
cipher = EVP.Cipher(alg='aes_256_cbc',
key='\x00System/Library/Frameworks/GameKit.framework/GameK',
iv=chr(0)*32,
op=1) # 1:encode 0:decode
m = hashlib.md5()
with open(tmp_file, 'rb') as source:
with open(target_file, 'wb') as target:
while True:
buf = source.read()
if not buf:
break
target.write(cipher.update(buf))
m.update(buf)
target.write(cipher.final())
subprocess.check_call(["rm", tmp_file])
content_hash = m.hexdigest().upper()
try:
with open(hash_file, 'r') as _hash:
if _hash.read() == content_hash:
return
except IOError:
pass
with open(hash_file, 'w') as _hash:
_hash.write(content_hash)
print ' ', target_file, 'changed\n\tmd5:', content_hash