我使用此代碼來加密plist文件,但我發現無論關鍵是什麼,通過AES的值不會改變,有人可以幫助我嗎?M2Crypto的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
歡迎來到Stackoverflow,熊。請看看你的問題的編輯(謝謝你們)。 –