JasyptCustomDigesterConfig.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.utils.crypt;

  21. import java.security.Provider;

  22. import org.jasypt.digest.config.DigesterConfig;
  23. import org.jasypt.salt.SaltGenerator;

  24. /**
  25.  * JasyptCustomDigesterConfig
  26.  *
  27.  * @author Poli Andrea (apoli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public class JasyptCustomDigesterConfig implements DigesterConfig {

  32.     private CryptConfig config;
  33.     private JasyptCustomSaltGenerator customSaltGenerator;
  34.    
  35.     public JasyptCustomDigesterConfig(CryptConfig config, JasyptCustomSaltGenerator customSaltGenerator) {
  36.         this.config = config;
  37.         this.customSaltGenerator = customSaltGenerator;
  38.     }
  39.    
  40.     @Override
  41.     public String getAlgorithm() {
  42.         String digestAlgorithm = this.config.getDigestAlgorithm();
  43.         if(digestAlgorithm==null) {
  44.             digestAlgorithm = "SHA-256"; // default
  45.         }
  46.         return digestAlgorithm;
  47.     }

  48.     @Override
  49.     public Boolean getInvertPositionOfPlainSaltInEncryptionResults() {
  50.         return false;
  51.     }

  52.     @Override
  53.     public Boolean getInvertPositionOfSaltInMessageBeforeDigesting() {
  54.         return false;
  55.     }

  56.     @Override
  57.     public Integer getIterations() {
  58.         if(this.config.getIteration()!=null && this.config.getIteration()>0) {
  59.             return this.config.getIteration().intValue();
  60.         }
  61.         return null;
  62.     }

  63.     @Override
  64.     public Integer getPoolSize() {
  65.         return null;
  66.     }

  67.     @Override
  68.     public Provider getProvider() {
  69.         return null;
  70.     }

  71.     @Override
  72.     public String getProviderName() {
  73.         return null;
  74.     }

  75.     @Override
  76.     public SaltGenerator getSaltGenerator() {
  77.         return this.customSaltGenerator;
  78.     }

  79.     @Override
  80.     public Integer getSaltSizeBytes() {
  81.         if(this.config.getSaltLength()!=null && this.config.getSaltLength()>0) {
  82.             return this.config.getSaltLength().intValue();
  83.         }
  84.         return null;
  85.     }

  86.     @Override
  87.     public Boolean getUseLenientSaltSizeCheck() {
  88.         return false;
  89.     }
  90.    
  91. }