Esempio n. 1
0
  public void Enc(String input_filename, String output_filename, String keystorename) {
    readKeystore(keystorename);
    buffer = new byte[n.bitLength() / 8 - (n.bitLength() % 8 == 0 ? 1 : 0)];
    int out_bytes = n.bitLength() / 8 + (n.bitLength() % 8 != 0 ? 1 : 0);

    FileInputStream input;
    FileOutputStream output;
    BigInteger number;
    try {
      input = new FileInputStream(input_filename);
      output = new FileOutputStream(output_filename);

      int bytes = 0;
      while ((bytes = input.read(buffer)) != -1) {
        if (bytes != buffer.length) for (int i = bytes; i < buffer.length; i++) buffer[i] = 0;
        number = new BigInteger(1, buffer);
        number = fastPower(number, e);
        byte[] num_bytes = number.toByteArray();
        if (num_bytes[0] == 0 && num_bytes.length != 1)
          num_bytes = Arrays.copyOfRange(num_bytes, 1, num_bytes.length);
        for (int i = 0; i < out_bytes - num_bytes.length; i++) output.write(new byte[] {0});
        output.write(num_bytes);
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }