Aes工具类

package com.tigeriot.ssldemo;

import java.io.UnsupportedEncodingException;

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

import org.springframework.util.Base64Utils;

/**
 * 
 * created by Jeeson
 *
 */
public class AesUtils {


	/**
	 * 根据IMEI获取AES code
	 * 
	 * @param content
	 * @return
	 */
	public static byte[] aesEncrypt(String content,String aeskey) {
		try {
			Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
			SecretKeySpec key = new SecretKeySpec(Base64Utils.decodeFromString(aeskey), "AES");
			cipher.init(Cipher.ENCRYPT_MODE, key);
			byte[] result = cipher.doFinal(content.getBytes("utf-8"));
			return result;
		} catch (Exception e) {
			// e.printStackTrace();
			return null;
		}

	}

	/**
	 * 根据AES_CODE获取IMEI
	 * new String()变回字符串
	 * @param content
	 * @return
	 */
	public static byte[] aseDecrypt(byte[] content,String aeskey) {
		try {
			Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
			SecretKeySpec key = new SecretKeySpec(Base64Utils.decodeFromString(aeskey), "AES");
			cipher.init(Cipher.DECRYPT_MODE, key);
			return cipher.doFinal(content);
		} catch (Exception e) {
			// e.printStackTrace();
			return null;
		}

	}

	public static void main(String[] args) throws UnsupportedEncodingException {

		// System.out.println(new
		// String(Base64Utils.decodeFromString(AseCrypto.SEC_KEY)));



	}
}

你可能感兴趣的:(工具类,java,开发语言)