Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.security.InvalidKeyException;

import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;

public class Main {
    private static byte[] Des(byte[] byteData, byte[] byteKey, int opmode)
            throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException,
            IllegalBlockSizeException, BadPaddingException {
        Cipher cipher = null;
        try {
            SecretKeySpec desKey = new SecretKeySpec(byteKey, "DES");

            cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
            cipher.init(opmode, desKey);

            return cipher.doFinal(byteData);
        } finally {
            cipher = null;
        }
    }
}