Java examples for Security:DES
des3 Decode ECB
//package com.java2s; import java.security.Key; import javax.crypto.Cipher; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESedeKeySpec; public class Main { public static void main(String[] argv) throws Exception { byte[] key = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; byte[] data = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; System.out.println(java.util.Arrays.toString(ees3DecodeECB(key, data)));/* w w w . j a v a2s .c o m*/ } public static byte[] ees3DecodeECB(byte[] key, byte[] data) throws Exception { Key deskey = null; DESedeKeySpec spec = new DESedeKeySpec(key); SecretKeyFactory keyfactory = SecretKeyFactory .getInstance("desede"); deskey = keyfactory.generateSecret(spec); Cipher cipher = Cipher.getInstance("desede" + "/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, deskey); byte[] bOut = cipher.doFinal(data); return bOut; } }