Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

public class Main {
    public static byte[] TriDesDecryption(byte[] byteKey, byte[] dec) {
        try {
            byte[] en_key = new byte[24];
            if (byteKey.length == 16) {
                System.arraycopy(byteKey, 0, en_key, 0, 16);
                System.arraycopy(byteKey, 0, en_key, 16, 8);
            }
            SecretKey key = new SecretKeySpec(en_key, "DESede");
            Cipher dcipher = Cipher.getInstance("DESede/ECB/NoPadding");
            dcipher.init(Cipher.DECRYPT_MODE, key);

            byte[] de_b = dcipher.doFinal(dec);

            return de_b;
        } catch (Exception e) {
            e.printStackTrace();

        }
        return null;
    }
}