Java DES des3EncodeECB(byte[] key, byte[] data)

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

Description

des Encode ECB

License

Apache License

Declaration

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

Method Source Code


//package com.java2s;
//License from project: Apache License 

import javax.crypto.Cipher;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;

import java.security.Key;

public class Main {

    public static byte[] des3EncodeECB(byte[] key, byte[] data) throws Exception {
        Key deskey = null;//w  w w  .j  av  a 2 s . c o  m
        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;
    }
}

Related

  1. desEncrypt(byte[] data, String encryptKey)
  2. desEncrypt(byte[] input, String password)
  3. desEncrypt(String content, String key)