des Decode ECB - Android java.security

Android examples for java.security:DES

Description

des Decode ECB

Demo Code


//package com.java2s;
import java.security.Key;

import javax.crypto.Cipher;

import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;

import android.util.Base64;

public class Main {

    public static byte[] desDecodeECB(byte[] key, byte[] data)
            throws Exception {
        Key deskey = null;/* w ww .ja va2 s. c o m*/
        DESedeKeySpec spec = new DESedeKeySpec(key);
        SecretKeyFactory keyfactory = SecretKeyFactory
                .getInstance("desede");
        deskey = keyfactory.generateSecret(spec);
        Cipher cipher = Cipher.getInstance("desede" + "/ECB/NoPadding");
        cipher.init(Cipher.DECRYPT_MODE, deskey);
        byte[] bOut = cipher.doFinal(Base64.decode(data, Base64.DEFAULT));
        return bOut;
    }
}

Related Tutorials