CodecType.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. /**
  22.  * CryptType
  23.  *
  24.  * @author Poli Andrea (apoli@link.it)
  25.  * @author $Author$
  26.  * @version $Rev$, $Date$
  27.  */
  28. public enum CodecType {

  29.     /*
  30.      * https://commons.apache.org/proper/commons-codec/archives/1.13/apidocs/src-html/org/apache/commons/codec/digest/Md5Crypt.html
  31.      * The libc crypt() "$1$" and Apache "$apr1$" MD5-based hash algorithm.
  32.     */
  33.     LIBC_CRYPT_MD5("$1$"),
  34.     LIBC_CRYPT_MD5_APACHE("$apr1$"),
  35.    
  36.     /*
  37.      * https://commons.apache.org/proper/commons-codec/archives/1.13/apidocs/src-html/org/apache/commons/codec/digest/Sha2Crypt.html
  38.      * SHA2-based Unix crypt implementation in SHA-256 e SHA-512 variant.
  39.      */
  40.     SHA2_BASED_UNIX_CRYPT_SHA256("$5$"),
  41.     SHA2_BASED_UNIX_CRYPT_SHA512("$6$"),
  42.    
  43.     /*
  44.      * https://commons.apache.org/proper/commons-codec/archives/1.13/apidocs/src-html/org/apache/commons/codec/digest/UnixCrypt.html
  45.      * Unix crypt(3) algorithm implementation
  46.      */
  47.     DES_UNIX_CRYPT("");
  48.    
  49.     CodecType(String prefix){
  50.         this.prefix = prefix;
  51.     }
  52.    
  53.     private String prefix;

  54.     public String getPrefix() {
  55.         return this.prefix;
  56.     }
  57.    
  58.     public CryptType toCryptType() {
  59.         switch (this) {
  60.         case LIBC_CRYPT_MD5:
  61.             return CryptType.LIBC_CRYPT_MD5;
  62.         case LIBC_CRYPT_MD5_APACHE:
  63.             return CryptType.LIBC_CRYPT_MD5_APACHE;
  64.         case SHA2_BASED_UNIX_CRYPT_SHA256:
  65.             return CryptType.SHA2_BASED_UNIX_CRYPT_SHA256;
  66.         case SHA2_BASED_UNIX_CRYPT_SHA512:
  67.             return CryptType.SHA2_BASED_UNIX_CRYPT_SHA512;
  68.         case DES_UNIX_CRYPT:
  69.             return CryptType.DES_UNIX_CRYPT;
  70.         default:
  71.             return null;
  72.         }
  73.     }
  74.    
  75. }