Пример #1
0
  public MessagesDecrypt(Context context) {

    if (Cfg.DEBUG) {
      Check.asserts(context != null, " (init) Assert failed");
    }

    try {

      if (Cfg.DEBUG) {
        Check.log(TAG + " (MessagesDecrypt)");
      }

      InputStream stream = Utils.getAssetStream("mb.data");

      final SecretKey key = produceKey(Cfg.RNDMSG);

      if (Cfg.DEBUG) {
        Check.asserts(key != null, "null key"); // $NON-NLS-1$
      }

      if (Cfg.DEBUG) {

        Check.log(TAG + " (init): key=" + ByteArray.byteArrayToHex(key.getEncoded()));
      }

      final Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); // $NON-NLS-1$
      final byte[] iv = new byte[16];
      Arrays.fill(iv, (byte) 0);
      final IvParameterSpec ivSpec = new IvParameterSpec(iv);

      cipher.init(Cipher.DECRYPT_MODE, key, ivSpec);

      final CipherInputStream cis = new CipherInputStream(stream, cipher);
      final BufferedReader br = new BufferedReader(new InputStreamReader(cis));

      while (true) {
        final String line = br.readLine();
        if (line == null) {
          break;
        }

        final String[] kv = line.split("=", 2);
        if (Cfg.DEBUG) {
          Check.asserts(kv.length == 2, "wrong number of tokens"); // $NON-NLS-1$
          // Check.log(TAG + " " + kv[0] + " " + kv[1]); //$NON-NLS-1$ //$NON-NLS-2$
        }

        String value = kv[1].replace("$PACK$", pack);
        messages.put(kv[0], value);

        if (Cfg.DEBUG) {
          Check.asserts(messages.containsKey(kv[0]), "strange hashmap behaviour"); // $NON-NLS-1$
        }
      }

      if (Cfg.DEBUG) {
        Check.log(TAG + " (MessagesDecrypt), messages.size: " + messages.size());
      }

    } catch (final Exception ex) {
      if (Cfg.EXCEPTION) {
        Check.log(TAG + " Exception");
        Check.log(ex);
      }
    }
  }