Here you can find the source of encryptToBytes(String key, String src)
public static byte[] encryptToBytes(String key, String src) throws Exception
//package com.java2s; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; public class Main { private final static String encoding = "utf-8"; private static byte[] iv = { 1, 2, 3, 4, 5, 6, 7, 8 }; public static byte[] encryptToBytes(String key, String src) throws Exception { return encrypt(key.getBytes(), src.getBytes(encoding)); }//from w w w . j av a 2s . co m private static byte[] encrypt(byte[] key, byte[] src) throws Exception { IvParameterSpec zeroIv = new IvParameterSpec(iv); SecretKeySpec spec = new SecretKeySpec(key, "DES"); Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, spec, zeroIv); return cipher.doFinal(src); } }