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