Java Utililty Methods DES

List of utility methods to do DES

Description

The list of methods to do DES are organized into topic(s).

Method

byte[]des3EncodeECB(byte[] key, byte[] data)
des Encode ECB
Key deskey = null;
DESedeKeySpec spec = new DESedeKeySpec(key);
SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");
deskey = keyfactory.generateSecret(spec);
Cipher cipher = Cipher.getInstance("desede" + "/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, deskey);
byte[] bOut = cipher.doFinal(data);
return bOut;
...
byte[]desEncrypt(byte[] data, String encryptKey)
des Encrypt
try {
    SecureRandom sr = new SecureRandom();
    DESKeySpec dks = new DESKeySpec(encryptKey.getBytes("UTF-8"));
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
    SecretKey key = keyFactory.generateSecret(dks);
    Cipher cipher = Cipher.getInstance("DES");
    cipher.init(Cipher.ENCRYPT_MODE, key, sr);
    return cipher.doFinal(data);
...
byte[]desEncrypt(byte[] input, String password)
des Encrypt
return doDes(Cipher.ENCRYPT_MODE, input, password);
byte[]desEncrypt(String content, String key)
des Encrypt
try {
    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());
...