Android DES encrypt encryptDES(String encryptString, String encryptKey)

Here you can find the source of encryptDES(String encryptString, String encryptKey)

Description

encrypt DES

Declaration

public static String encryptDES(String encryptString, 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 String encryptDES(String encryptString, 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(encryptString.getBytes());

        //            return Base64.encode(encryptedData);
        return byte2HexString(encryptedData);
    }//from ww  w .j a v  a2  s .com

    public static String byte2HexString(byte[] b) {
        StringBuffer sb = new StringBuffer();
        int length = b.length;
        for (int i = 0; i < b.length; i++) {
            String stmp = Integer.toHexString(b[i] & 0xff);
            if (stmp.length() == 1)
                sb.append("0" + stmp);
            else
                sb.append(stmp);
        }
        return sb.toString();
    }
}

Related

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