decrypt DES File - Java File Path IO

Java examples for File Path IO:File Operation

Description

decrypt DES File

Demo Code


//package com.java2s;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

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

    public static byte[] decryptDESFile(byte[] decryptData,
            String decryptKey) throws Exception {

        IvParameterSpec zeroIv = new IvParameterSpec(iv);
        SecretKeySpec key = new SecretKeySpec(decryptKey.getBytes(), "DES");
        Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, key, zeroIv);
        byte decryptedResult[] = cipher.doFinal(decryptData);
        return decryptedResult;
    }// w  ww.  j ava  2s  .com
}

Related Tutorials