使用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);