Skip to content

Instantly share code, notes, and snippets.

@xperylab
Created July 28, 2021 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xperylab/67d1a6da85de27eeb65bf7b8dba68fc6 to your computer and use it in GitHub Desktop.
Save xperylab/67d1a6da85de27eeb65bf7b8dba68fc6 to your computer and use it in GitHub Desktop.
PM : get main key from PinProtection strategy
import hashlib
import plistlib
from Crypto.Cipher import AES
salt = keychainVal['PinProtection.salt']
encMainKey = keychainVal['PinProtection']
def getMainKeyFromPinProtection(pin):
iKey = hashlib.scrypt(pin, salt=salt, n=32768, r=8, p=1, maxmem=33*1024*1024, dklen=32)
cipher = AES.new(ikey, AES.MODE_CTR, initial_value=encMainKey[:IVsize], nonce=b'')
mainKey = bytes(plistlib.loads(cipher.decrypt(encMainKey[IVsize:])))
return mainKey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment