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 javax.crypto.Cipher;

import javax.crypto.spec.SecretKeySpec;

public class Main {
    private static byte[] Aes(byte[] byteData, byte[] byteKey, int opmode) throws Exception {
        Cipher cipher = null;
        try {
            SecretKeySpec aesKey = new SecretKeySpec(byteKey, "AES");
            cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(opmode, aesKey);

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