Coverage Summary for Class: PasswordEncryptors (com.acciente.oacc.sql.internal.encryptor)

Class Class, % Method, % Line, %
PasswordEncryptors 100% (1/ 1) 33.3% (1/ 3) 11.1% (1/ 9)


1 /* 2  * Copyright 2009-2018, Acciente LLC 3  * 4  * Acciente LLC licenses this file to you under the 5  * Apache License, Version 2.0 (the "License"); you 6  * may not use this file except in compliance with the 7  * License. You may obtain a copy of the License at 8  * 9  * http://www.apache.org/licenses/LICENSE-2.0 10  * 11  * Unless required by applicable law or agreed to in 12  * writing, software distributed under the License is 13  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES 14  * OR CONDITIONS OF ANY KIND, either express or implied. 15  * See the License for the specific language governing 16  * permissions and limitations under the License. 17  */ 18 package com.acciente.oacc.sql.internal.encryptor; 19  20 import com.acciente.oacc.encryptor.PasswordEncryptor; 21 import com.acciente.oacc.encryptor.bcrypt.BCryptPasswordEncryptor; 22 import com.acciente.oacc.encryptor.jasypt.JasyptPasswordEncryptor; 23  24 import java.util.Arrays; 25 import java.util.List; 26  27 /** 28  * Internally used helper class to get an instance of the {@link PasswordEncryptor} identified 29  * by the name of the {@link PasswordEncryptor}. This is where the NAME constant that is expected to 30  * be defined in every {@link PasswordEncryptor} implementation is used. 31  */ 32 public class PasswordEncryptors { 33  private static final int BCRYPT_MIN_COST_FACTOR = 10; 34  35  private static final String JASYPT_ALGORITHM = "SHA-256"; 36  private static final int JASYPT_ITERATIONS = 100000; 37  private static final int JASYPT_SALT_SIZE_BYTES = 16; 38  39  public static PasswordEncryptor getPasswordEncryptor(String encryptorName) { 40  if (encryptorName == null) { 41  throw new IllegalArgumentException("Encryptor name cannot be null"); 42  } 43  44  if (encryptorName.equalsIgnoreCase(BCryptPasswordEncryptor.NAME)) { 45  return BCryptPasswordEncryptor.newInstance(BCRYPT_MIN_COST_FACTOR); 46  } 47  48  if (encryptorName.equalsIgnoreCase(JasyptPasswordEncryptor.NAME)) { 49  return JasyptPasswordEncryptor.newInstance(JASYPT_ALGORITHM, JASYPT_ITERATIONS, JASYPT_SALT_SIZE_BYTES); 50  } 51  52  throw new IllegalArgumentException("Encryptor name " + encryptorName + " not recognized"); 53  } 54  55  public static List<String> getSupportedEncryptorNames() { 56  return Arrays.asList(BCryptPasswordEncryptor.NAME, JasyptPasswordEncryptor.NAME); 57  } 58 }