Android DES Decrypt decode(String key, byte[] data)

Here you can find the source of decode(String key, byte[] data)

Description

decode

Declaration

public static byte[] decode(String key, byte[] data) throws Exception 

Method Source Code

//package com.java2s;

import javax.crypto.Cipher;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import java.security.Key;
import java.security.spec.AlgorithmParameterSpec;

public class Main {
    public static final String ALGORITHM_DES = "DES/CBC/PKCS5Padding";

    public static byte[] decode(String key, byte[] data) throws Exception {
        try {/*w  w w  .  j  av  a 2  s .com*/
            DESKeySpec dks = new DESKeySpec(key.getBytes());
            SecretKeyFactory keyFactory = SecretKeyFactory
                    .getInstance("DES");
            Key secretKey = keyFactory.generateSecret(dks);
            Cipher cipher = Cipher.getInstance(ALGORITHM_DES);
            IvParameterSpec iv = new IvParameterSpec(key.getBytes());
            AlgorithmParameterSpec paramSpec = iv;
            cipher.init(Cipher.DECRYPT_MODE, secretKey, paramSpec);
            return cipher.doFinal(data);
        } catch (Exception e) {
            throw new Exception(e);
        }
    }
}

Related

  1. desDecodeCBC(byte[] key, byte[] keyiv, byte[] data)
  2. desDecodeECB(byte[] key, byte[] data)
  3. decryptDES(String decryptString, String decryptKey)
  4. decryptDESFile(byte[] decryptData, String decryptKey)
  5. decode(String key, String data)
  6. decrypt(byte[] key, byte[] src)
  7. encode(String key, String data)
  8. decryptBytes(String key, byte[] src)
  9. decryptEDE(byte[] key, byte[] src)