@@ -0,0 +1,2888 @@
+package leap.lang.security;%0A%0Aimport leap.lang.Strings;%0Aimport leap.lang.codec.Base64;%0A%0Aimport javax.crypto.*;%0Aimport javax.crypto.spec.DESedeKeySpec;%0Aimport javax.crypto.spec.IvParameterSpec;%0Aimport java.nio.charset.Charset;%0Aimport java.security.*;%0Aimport java.security.spec.InvalidKeySpecException;%0A%0A/**%0A * @author kael.%0A */%0Apublic class DESede %7B%0A    %0A    private final String cipherType;%0A%0A    private DESede(String cipherType) %7B%0A        this.cipherType = cipherType;%0A    %7D%0A%0A    public static DESede create(String cipherType, Provider ... providers)%7B%0A        if(null != providers && providers.length %3E 0)%7B%0A            for(Provider provider : providers) %7B%0A                Security.addProvider(provider);%0A            %7D%0A        %7D%0A        return new DESede(cipherType);%0A    %7D%0A    %0A    public static DESede create()%7B%0A        return new DESede(%22DESede/ECB/PKCS5Padding%22);%0A    %7D%0A    %0A    public String encryptToBase64(String key, String iv, String plaintext) throws IllegalBlockSizeException, BadPaddingException, InvalidKeySpecException, InvalidKeyException %7B%0A        return Base64.encode(encrypt(key, iv, plaintext));%0A    %7D%0A%0A    public String decryptToBase64(String key, String iv, byte%5B%5D encrypted) throws InvalidKeySpecException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException %7B%0A        return Base64.encode(decrypt(key,iv, encrypted));%0A    %7D%0A    %0A    public byte%5B%5D encrypt(String key, String iv, String plaintext) throws InvalidKeySpecException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException %7B%0A        Cipher cipher = initCipher(key, iv, Cipher.ENCRYPT_MODE);%0A        return cipher.doFinal(plaintext.getBytes());%0A    %7D%0A%0A    public byte%5B%5D decrypt(String key, String iv, byte%5B%5D encrypted) throws InvalidKeySpecException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException %7B%0A        Cipher cipher = initCipher(key, iv, Cipher.DECRYPT_MODE);%0A        return cipher.doFinal(encrypted);%0A    %7D%0A    %0A    protected Cipher initCipher(String key, String iv, int mode) throws InvalidKeySpecException, InvalidKeyException %7B%0A        try %7B%0A            DESedeKeySpec dks = new DESedeKeySpec(key.getBytes(Charset.forName(%22UTF-8%22)));%0A            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(%22DESede%22);%0A            SecretKey securekey = keyFactory.generateSecret(dks);%0A            Cipher cipher = Cipher.getInstance(cipherType);%0A            if(Strings.isNotEmpty(iv))%7B%0A                SecureRandom sr = new SecureRandom();%0A                IvParameterSpec ivSpec = new IvParameterSpec(iv.getBytes());%0A                cipher.init(mode, securekey, ivSpec, sr);%0A            %7Delse %7B%0A                cipher.init(mode, securekey);%0A            %7D%0A            return cipher;%0A        %7D catch (InvalidAlgorithmParameterException %7C NoSuchPaddingException %7C NoSuchAlgorithmException e) %7B%0A            throw new RuntimeException(e);%0A        %7D%0A    %7D%0A%7D%0A

add DESede Utils