papegaaij commented on a change in pull request #462: URL: https://github.com/apache/wicket/pull/462#discussion_r593776954
########## File path: wicket-util/src/main/java/org/apache/wicket/util/crypt/AESCrypt.java ########## @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.util.crypt; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import javax.crypto.SecretKey; +import javax.crypto.spec.IvParameterSpec; + +/** + * AES based {@link ICrypt} encrypt and decrypt strings such as passwords or URL segments. + * Based on http://stackoverflow.com/a/992413 + * + * @see ICrypt + */ +class AESCrypt extends AbstractJceCrypt +{ + + private final SecretKey secretKey; + private final String algorithm; + private final int ivSize; + + + /** + * Constructor + * + * @param secretKey + * The {@link SecretKey} to use to initialize the {@link Cipher}. + */ + public AESCrypt(SecretKey secretKey) + { + this(secretKey, "AES/CBC/PKCS5Padding", 16); + } + + /** + * Constructor + * + * @param secretKey + * The {@link SecretKey} to use to initialize the {@link Cipher}. + * @param algorithm + * The cipher algorithm to use, for example "AES/CBC/PKCS5Padding". + * @param ivSize + * The size of the Initialization Vector to use with the cipher. Review comment: But that's only because the lookup and unit of the Cipher are in `buildCipher`. IMHO that method does not really make things easier to understand. I think the code would be better with that method unlined. Then you can bring the Cipher lookup to the front and use that to get the block size. This is just my opinion. If you do decide to keep the method, then rename the field to `blockSize`, as that is what it is. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org