返回顶部

Java 对称加密

代码

public String encrypt(String content) throws Exception {

        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");

        SecretKey secretKey = new SecretKeySpec("自定义内容".substring(0,32).getBytes(), "AES");

        IvParameterSpec iv = new IvParameterSpec("自定义内容".substring(0,16).getBytes());

        cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);

        byte[] encrypted = cipher.doFinal(content.getBytes());

        return new String(Base64.getEncoder().encode(encrypted));

    }
posted @ 2022-08-08 09:41  凑数的园丁  阅读(424)  评论(0编辑  收藏  举报