List of usage examples for org.apache.shiro.crypto BlowfishCipherService BlowfishCipherService
public BlowfishCipherService()
| Attribute | Value |
|---|---|
| #setKeySize keySize | 128 bits |
| #setBlockSize blockSize | 64 bits (required for Blowfish ) |
| #setMode mode | OperationMode#CBC CBC * |
| #setPaddingScheme paddingScheme | PaddingScheme#PKCS5 PKCS5 |
| #setInitializationVectorSize(int) initializationVectorSize | 64 bits |
| #setGenerateInitializationVectors(boolean) generateInitializationVectors | true ** |
From source file:org.lunifera.examples.kwiee.erp.module.core.services.internal.AdministrationServiceComponent.java
License:Open Source License
private String encodePassword(String password2Encode) { byte[] saltKey; int encryptedSecretLenght; int saltKeyLenght; BlowfishCipherService cipher = new BlowfishCipherService(); // generate key with default 256 bits size saltKey = cipher.generateNewKey(256).getEncoded(); saltKeyLenght = saltKey.length;/* w w w. j ava2s . c o m*/ // encrypt the secret ByteSource encryptedSecret = cipher.encrypt(CodecSupport.toBytes(password2Encode), saltKey); encryptedSecretLenght = encryptedSecret.getBytes().length; // create a destination array that is the size of the two arrays byte[] destination = new byte[saltKeyLenght + encryptedSecretLenght]; // copy ciphertext into start of destination (from pos 0, copy // ciphertext.length bytes) System.arraycopy(encryptedSecret.getBytes(), 0, destination, 0, encryptedSecretLenght); // copy mac into end of destination (from pos ciphertext.length, copy // mac.length bytes) System.arraycopy(saltKey, 0, destination, encryptedSecretLenght, saltKeyLenght); return Base64.encodeToString(destination); }
From source file:org.lunifera.examples.kwiee.erp.module.core.services.internal.AdministrationServiceComponent.java
License:Open Source License
protected String decodePassword(String password2Decode) { byte[] saltKey; BlowfishCipherService cipher = new BlowfishCipherService(); // generate key with default 256 bits size saltKey = cipher.generateNewKey(256).getEncoded(); byte[] decoded = Base64.decode(password2Decode); InputStream cipherIn = new ByteArrayInputStream(decoded); ByteArrayOutputStream plainOut = new ByteArrayOutputStream(); cipher.decrypt(cipherIn, plainOut, saltKey); byte[] decrypted = plainOut.toByteArray(); return decrypted.toString(); }