decrypt EDE - Android java.security

Android examples for java.security:EDE

Description

decrypt EDE

Demo Code


//package com.java2s;
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import javax.crypto.spec.IvParameterSpec;

public class Main {
    private static byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8 };

    private static byte[] decryptEDE(byte[] key, byte[] src)
            throws Exception {
        Key deskey = null;/*from w ww  .ja  va 2s .  c  o m*/
        DESedeKeySpec spec = new DESedeKeySpec(key);
        SecretKeyFactory keyfactory = SecretKeyFactory
                .getInstance("desede");
        deskey = keyfactory.generateSecret(spec);
        Cipher cipher = Cipher.getInstance("desede/CBC/PKCS5Padding");
        IvParameterSpec ips = new IvParameterSpec(iv);
        cipher.init(Cipher.DECRYPT_MODE, deskey, ips);
        return cipher.doFinal(src);
    }
}

Related Tutorials