集册 Java实例教程 加密DES文件

加密DES文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

558
加密DES文件
/*
NowJava.com 提 供
*/


//package com.nowjava;

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[] encryptDESFile(byte[] encryptdata,

            String encryptKey) throws Exception {

        IvParameterSpec zeroIv = new IvParameterSpec(iv);

        SecretKeySpec key = new SecretKeySpec(encryptKey.getBytes(), "DES");

        Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");

        cipher.init(Cipher.ENCRYPT_MODE, key, zeroIv);// 来 自 时代Java

        
展开阅读全文