1 /* 2 * This file is part of Waarp Project (named also Waarp or GG). 3 * 4 * Copyright (c) 2019, Waarp SAS, and individual contributors by the @author 5 * tags. See the COPYRIGHT.txt in the distribution for a full listing of 6 * individual contributors. 7 * 8 * All Waarp Project is free software: you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or (at your 11 * option) any later version. 12 * 13 * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY 14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 15 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License along with 18 * Waarp . If not, see <http://www.gnu.org/licenses/>. 19 */ 20 package org.waarp.common.crypto; 21 22 /** 23 * This class handles methods to crypt and decrypt messages with Blowfish 24 * (efficient: 4000/s both at 56 and 25 * 128 keysize).<br> 26 * <br> 27 * Usage:<br> 28 * <ul> 29 * <li>Create a Blowfish object: Blowfish key = new Blowfish();</li> 30 * <li>Create a key: 31 * <ul> 32 * <li>Generate: key.generateKey();<br> 33 * The method key.getSecretKeyInBytes() allow getting the key in Bytes.</li> 34 * <li>From an external source: key.setSecretKey(arrayOfBytes);</li> 35 * </ul> 36 * </li> 37 * <li>To crypt a String in a Base64 format: String myStringCrypt = 38 * key.cryptToString(myString);</li> 39 * <li>To decrypt one string from Base64 format to the original String: String 40 * myStringDecrypt = 41 * key.decryptStringInString(myStringCrypte);</li> 42 * </ul> 43 */ 44 public class Blowfish extends KeyObject { 45 /** 46 * This value could be between 32 and 448. But it seems it is blocked up to 47 * 128. 48 */ 49 private static final int KEY_SIZE = 56; // [32..448] 50 private static final String ALGO = "Blowfish"; 51 private static final String INSTANCE = "Blowfish"; 52 public static final String EXTENSION = "blf"; 53 54 @Override 55 public final String getAlgorithm() { 56 return ALGO; 57 } 58 59 @Override 60 public final String getInstance() { 61 return INSTANCE; 62 } 63 64 @Override 65 public final int getKeySize() { 66 return KEY_SIZE; 67 } 68 69 @Override 70 public final String getFileExtension() { 71 return EXTENSION; 72 } 73 }