怎樣才能使密鑰的長度不受限制
寫了個(gè)加密的方法,發(fā)現(xiàn)密鑰的長度有限制,有資料說必須是16的倍數(shù),否則報(bào)錯(cuò),怎樣才能使密鑰的長度不受限制
public?static?String?jdkAES_Encrypt(String?source,?String?secretKey)?{ ? ????????try?{ ????????????byte[]?keyBytes?=?secretKey.getBytes(); ????????????//?key轉(zhuǎn)換 ????????????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; ????}