怎样才能使密钥的长度不受限制
写了个加密的方法,发现密钥的长度有限制,有资料说必须是16的倍数,否则报错,怎样才能使密钥的长度不受限制
public static String jdkAES_Encrypt(String source, String secretKey) { try { byte[] keyBytes = secretKey.getBytes(); // key转换 Key key = new SecretKeySpec(keyBytes, "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] result = cipher.doFinal(source.getBytes()); System.out.println("密文Base64:" + Base64.encodeBase64String(result)); return Base64.encodeBase64String(result); } catch (Exception e) { e.printStackTrace(); } return null; }