Пример #1
0
 /**
  * 解密
  *
  * @param hexCipher 十六进制字符串形式密文
  * @param charset 明文字符编码
  * @param hexKey 十六进制字符串形式密钥
  * @return 明文
  * @throws Exception
  */
 public static String decrypt(String cipherHex, String charset, String hexKey) throws Exception {
   if (cipherHex == null || charset == null || hexKey == null) {
     return null;
   }
   return new String(
       decrypt(ByteFormat.hexToBytes(cipherHex), ByteFormat.hexToBytes(hexKey)), charset);
 }
Пример #2
0
  /**
   * 加密
   *
   * @param plain 明文
   * @param charset 明文字符编码
   * @param hexKey 十六进制字符串形式密钥
   * @return 十六进制字符串形式密文
   * @throws Exception
   */
  public static String encrypt(String plain, String charset, String hexKey) throws Exception {
    if (plain == null || charset == null || hexKey == null) {
      return null;
    }

    return ByteFormat.toHex(encrypt(plain.getBytes(charset), ByteFormat.hexToBytes(hexKey)));
  }
  /**
   * Returns the string, showing information for the given file.
   *
   * @param file the file
   * @return the name of the given file
   */
  protected String getFileLabel(File file) {
    String fileName = file.getName();
    long fileSize = file.length();

    ByteFormat format = new ByteFormat();
    String text = format.format(fileSize);

    return fileName + " (" + text + ")";
  }
Пример #4
0
  public static void main(String args[]) {
    String plainText =
        "dffrrereeeeeeeeeeeeeeeeeeeeeeeerererefffrererefffddfdfdfdfdfdfdf343434343434343ffffrerererere;l;l;ll;;l;l;lffffffffff4343434343434343434343ffffffffffffffffffffffffabcdefgddddddddddddddddddddsdssddssdsdsssddsddddddddddddsdsjj111gfgfgfffffff;llklklklklkkhghghghghgkkkkkkkkkkkkkkkkkkhghjffffffffffffffgao";
    byte key[] = "GdWb5dnxhUxFKcE4GqdhL23TndZFYXPy".getBytes();
    try {
      long t1 = System.currentTimeMillis();
      String cipherText = XXTea.encrypt(plainText, "UTF-8", ByteFormat.toHex(key));
      System.out.println(cipherText);

      String pText = XXTea.decrypt(cipherText, "UTF-8", ByteFormat.toHex(key));
      System.out.println(pText);
      long t2 = System.currentTimeMillis();
      System.out.println(t2 - t1);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
  /**
   * Updates progress bar progress line every time a progress event has been received.
   *
   * @param event the <tt>FileTransferProgressEvent</tt> that notified us
   */
  public void progressChanged(FileTransferProgressEvent event) {
    progressBar.setValue((int) event.getProgress());

    long transferredBytes = event.getFileTransfer().getTransferedBytes();
    long progressTimestamp = event.getTimestamp();

    ByteFormat format = new ByteFormat();
    String bytesString = format.format(transferredBytes);

    if ((progressTimestamp - lastSpeedTimestamp) >= SPEED_CALCULATE_DELAY) {
      lastProgressSpeed = Math.round(calculateProgressSpeed(transferredBytes));

      this.lastSpeedTimestamp = progressTimestamp;
      this.lastTransferredBytes = transferredBytes;
    }

    if ((progressTimestamp - lastEstimatedTimeTimestamp) >= SPEED_CALCULATE_DELAY
        && lastProgressSpeed > 0) {
      lastEstimatedTime =
          Math.round(
              calculateEstimatedTransferTime(
                  lastProgressSpeed, transferredFileSize - transferredBytes));

      lastEstimatedTimeTimestamp = progressTimestamp;
    }

    progressBar.setString(getProgressLabel(bytesString));

    if (lastProgressSpeed > 0) {
      progressSpeedLabel.setText(
          resources.getI18NString("service.gui.SPEED") + format.format(lastProgressSpeed) + "/sec");
      progressSpeedLabel.setVisible(true);
    }

    if (lastEstimatedTime > 0) {
      estimatedTimeLabel.setText(
          resources.getI18NString("service.gui.ESTIMATED_TIME")
              + GuiUtils.formatSeconds(lastEstimatedTime * 1000));
      estimatedTimeLabel.setVisible(true);
    }
  }
  /**
   * Returns the string, showing information for the given file.
   *
   * @param fileName the name of the file
   * @param fileSize the size of the file
   * @return the name of the given file
   */
  protected String getFileLabel(String fileName, long fileSize) {
    ByteFormat format = new ByteFormat();
    String text = format.format(fileSize);

    return fileName + " (" + text + ")";
  }