public class diaoduService { //Java中不支持Zeropadding填充,使用NoPadding处理,结果都是一样的 private static final String DEFAULT_CIPHER_ALGORITHM = "AES/ECB/NoPadding";// 默认的加密算法 /** * AES 加密操作 * * @param content 待加密内容 * @param password 加密密码 * @return */ public String encrypt(String content, String password) { try { Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);// 创建密码器 int blockSize = cipher.getBlockSize(); byte[] byteContent = content.getBytes(); int plaintextLength = byteContent.length; if (plaintextLength % blockSize != 0) { plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize)); } byte[] plaintext = new byte[plaintextLength]; System.arraycopy(byteContent, 0, plaintext, 0, byteContent.length); cipher.init
Java使用 使用AES加解密算法,加密模式:ECB,填充:Zeropadding
最新推荐文章于 2024-09-30 10:17:59 发布