예제 #1
0
  protected void engineSetMode(String mode) {
    String modeName = Strings.toUpperCase(mode);

    if (modeName.equals("ECB")) {
      ivLength = 0;
      cipher = new PaddedBufferedBlockCipher(cipher.getUnderlyingCipher());
    } else if (modeName.equals("CBC")) {
      ivLength = cipher.getUnderlyingCipher().getBlockSize();
      cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(cipher.getUnderlyingCipher()));
    } else if (modeName.startsWith("OFB")) {
      ivLength = cipher.getUnderlyingCipher().getBlockSize();
      if (modeName.length() != 3) {
        int wordSize = Integer.parseInt(modeName.substring(3));

        cipher =
            new PaddedBufferedBlockCipher(
                new OFBBlockCipher(cipher.getUnderlyingCipher(), wordSize));
      } else {
        cipher =
            new PaddedBufferedBlockCipher(
                new OFBBlockCipher(cipher.getUnderlyingCipher(), 8 * cipher.getBlockSize()));
      }
    } else if (modeName.startsWith("CFB")) {
      ivLength = cipher.getUnderlyingCipher().getBlockSize();
      if (modeName.length() != 3) {
        int wordSize = Integer.parseInt(modeName.substring(3));

        cipher =
            new PaddedBufferedBlockCipher(
                new CFBBlockCipher(cipher.getUnderlyingCipher(), wordSize));
      } else {
        cipher =
            new PaddedBufferedBlockCipher(
                new CFBBlockCipher(cipher.getUnderlyingCipher(), 8 * cipher.getBlockSize()));
      }
    } else {
      throw new IllegalArgumentException("can't support mode " + mode);
    }
  }
예제 #2
0
 protected int engineGetBlockSize() {
   return cipher.getBlockSize();
 }