コード例 #1
0
  @Override
  public boolean openInputStream() {

    if (filename != null) {
      super.openInputStream();
    }

    setup(); // make sure algorithm and keys/states are reset
    count = 0;
    countLastRead = SIZE;
    actualSize = SIZE;
    outAlgoBufferIx = outAlgoBuffer.length;
    open = true;
    return open;
  }
コード例 #2
0
ファイル: AES.java プロジェクト: cryptopony/jrandtest
  @Override
  public byte readByte() {
    if (!isOpen()) {
      return -1;
    }

    if (filename == null && count > maxCount) {
      open = false;
      return -1;
    }

    byte prng = -1;

    /*
     * encrypt file if exists
     */
    if (filename != null) {
      if (countLastRead == actualSize) { // end of buffer?
        super.readByte(); // read & fill buffer from file
        if (!isOpen()) {
          return -1;
        }
        countLastRead = 0;
        try {
          algo.update(buffer, 0, actualSize, buffer);
        } catch (ShortBufferException e) {
          throw new IllegalStateException(e);
        } // encrypt it
      }

      prng = buffer[countLastRead++];
      count++;
      return prng;
    }

    /*
     * we have no real filename to encrypt
     */
    if (outAlgoBufferIx == outAlgoBuffer.length) {
      outAlgoBuffer = algo.update(inAlgoBuffer);
      outAlgoBufferIx = 0;
    }

    prng = outAlgoBuffer[outAlgoBufferIx++];
    count++;
    return prng;
  }
コード例 #3
0
  @Override
  public void setupKeys() {

    super.setupKeys();
  }