code: def jks_pkey_encrypt(key, password_str):
      
      password_bytes = password_str.encode('utf-16be') # Java chars are UTF-16BE code units
      iv = os.urandom(20)
  
      key = bytearray(key)
      xoring = zip(key, _jks_keystream(iv, password_bytes))
      data = bytearray([d^k for d,k in xoring])
  
      check = hashlib.sha1(bytes(password_bytes + key)).digest()
      return bytes(iv + data + check)
docs: Encrypts the private key with password protection algorithm used by JKS keystores.