Android DES encrypt encryptDESFile(byte[] encryptdata, String encryptKey)

Here you can find the source of encryptDESFile(byte[] encryptdata, String encryptKey)

Description

encrypt DES File

Declaration

public static byte[] encryptDESFile(byte[] encryptdata,
            String encryptKey) throws Exception 

Method Source 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[] 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);
        byte[] encryptedData = cipher.doFinal(encryptdata);

        //            return Base64.encode(encryptedData);
        return encryptedData;
    }//from w w w  . j  a v a 2  s .  co m
}

Related

  1. desEncodeCBC(byte[] key, byte[] keyiv, byte[] data)
  2. desEncodeECB(byte[] key, byte[] data)
  3. decrypt(String property)
  4. encrypt(String property)
  5. encryptDES(String encryptString, String encryptKey)
  6. encryptEDE(byte[] key, byte[] src)
  7. encrypt(byte[] key, byte[] src)
  8. encryptToBytes(String key, String src)