Here you can find the source of desEncrypt(String content, String key)
public static byte[] desEncrypt(String content, String key)
//package com.java2s; //License from project: Apache License import java.security.SecureRandom; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpec; public class Main { public static byte[] desEncrypt(String content, String key) { try {//from w w w . ja v a2 s .c o m SecureRandom random = new SecureRandom(); DESKeySpec desKey = new DESKeySpec(key.getBytes()); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES"); SecretKey securekey = keyFactory.generateSecret(desKey); Cipher cipher = Cipher.getInstance("DES"); cipher.init(Cipher.ENCRYPT_MODE, securekey, random); byte[] result = cipher.doFinal(content.getBytes()); return result; } catch (Throwable e) { e.printStackTrace(); } return null; } }