阅读背景:

JAVA AES/ECB/PKCS5Padding 加密 PHP实现_daivull的专栏

来源:互联网 
java代码
public class Encryption {

	private static final String ALGORITHM = "AES";
	
	public static SecretKey getSecretKey(String key) throws Exception{
		SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), ALGORITHM);
        return secretKeySpec;
    }
	
	public static byte[] encryptionByAES(byte[] data,String key){
        try {
            // 创建解密器
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            // 获取Key
            SecretKey secretKey = getSecretKey(key);
            cipher.init(Cipher.ENCRYPT_MODE,secretKey);
            return cipher.doFinal(data);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("method AESUtils.decryptionByAES is error");
        }
    }
	
    public static void main(String[] args) {

    	String str = "sadfsdfsdfsdfsf";
        
        String key = "1234567891234567";

        byte[] ret = encryptionByAES(str.getBytes(), key);
        
        String encryptedStr = Base64.getEncoder().encodeToString(ret);
        
        System.out.println(encryptedStr);

    }
}
public class Encryption {

	pri



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: