Because I always need to do this for passwords in files and various utilities I thought I would post the code. Note: it is more secure to encrypt one way (cryptographic hashing) this is for simple no hassle cases. package za.co.test.common.util; import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; import java.security.Key; import java.security.NoSuchAlgorithmException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; public class EncryptionUtil { private static final byte[] SECRET_KEY = "TESTKEY2013StormersRugby".getBytes(); public static byte[] encryptToByteArray(String input) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException, NoS...
The Incident Archive: A blog to store my knowledge on the errors that I fix on a daily basis