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

转载于:https://www.cnblogs.com/mortre/p/6410808.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值