使用java des加密算法時,出現javax.crypto.IllegalBlockSizeException: Input length not multiple of 8 bytes錯誤,
必須要是8的整數倍,我想可能是在加密、解密時防止字符之間錯誤www.twitterchina.net。解決辦法只能將字符串封裝成8的整數倍了
//Exception in thread "main" javax.crypto.IllegalBlockSizeException: Input length not multiple of 8 bytes
String hello="生成秘鑰生。";
int len=hello.getBytes("utf-8").length;
if(len%8!=0){
System.out.println("不是8的整數倍");
byte[] hellotemp=new byte[len+(8-len%8)];
for(int i=0;i<len;i++){
hellotemp[i]=hello.getBytes("utf-8")[i];
}
hello=new String(hellotemp,"utf-8");
}
System.out.println(hello.getBytes("utf-8").length);