javax.crypto.IllegalBlockSizeException: Input length not multiple of 8 bytes


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

来源:www.javait.org


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM