protected void engineSetPadding(String padding) throws NoSuchPaddingException { String paddingName = Strings.toUpperCase(padding); if (paddingName.equals("NOPADDING")) { cipher = new BufferedBlockCipher(cipher.getUnderlyingCipher()); } else if (paddingName.equals("PKCS5PADDING") || paddingName.equals("PKCS7PADDING") || paddingName.equals("ISO10126PADDING")) { cipher = new PaddedBufferedBlockCipher(cipher.getUnderlyingCipher()); } else if (paddingName.equals("WITHCTS")) { cipher = new CTSBlockCipher(cipher.getUnderlyingCipher()); } else { throw new NoSuchPaddingException("Padding " + padding + " unknown."); } }
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); } }