package com.saye.hospitalgd.commons.encrypt;

import org.apache.commons.codec.binary.Base64;

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

public class EncryptUtil {

	// AES ecb模式解密  key:秘钥 initVector:偏移量  encrypted：加密内容
    public static String decrypt(String key,String initVector,String encrypted) {
    	try {
    		IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
    		SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
    		
    		Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
    		cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
    		byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted));
     
    		return new String(original);
    	} catch (Exception ex) {
    		ex.printStackTrace();
    	}
    	return null;
    }
 
    public static void main(String[] args) throws Exception {
    	System.out.println(decrypt("a6xdabhysfescfbu","encryptionIntVec","oYzamqnnyJ8GG6646PDYBQ=="));
    }
}