Input length must be multiple of 8 when decrypting with padded cipher
Des密码加密报错:Input length must be multiple of 8 when decrypting with padded cipher
错误原因:
- 判断加密代码上一句执行的是否是解密
我的是先执行解密,然后加密,报的这个错误,原本是直接加密就好的 - 针对文件加密多写了一个字符
附上加密解密代码:
解密:直接调用DesUtil的decrypt方法即可
// DES解密key,限定24位
String DES_KEY = "WfJTKO9S4eLkrPz2JKrAnzdb";
// DES解密iv,限定8位
String DES_IV = "D076D35C";
String pwd = DesUtil.decrypt(userDto.getPsw(), ContentSecurityConstants.DES_KEY,ContentSecurityConstants.DES_IV);
加密:
- 生成盐值
public static final Integer SALT_SIZE = 8;/*** 生成随机的Byte[]作为salt.* * @param numBytes* byte数组的大小*/public static byte[] generateSalt(int numBytes) {Validate.isTrue(numBytes > 0, "numBytes argument must be a positive integer (1 or larger)", numBytes);byte[] bytes = new byte[numBytes];random.nextBytes(bytes);return bytes;}public static byte[] generateSaltFix() {return generateSalt(SALT_SIZE);}// 盐值byte[] salt = generateSaltFix();
- PasswdService接口类
/*** 密码* @param saltBytes 混淆码数组* @param rawPass 明文密码* @return 密码*/public String entryptPassword(byte[] saltBytes,String rawPass);
- PasswdServiceImpl接口实现类
@Overridepublic String entryptPassword(byte[] saltBytes, String rawPass) {String encPass = CredentialsDigest.digest(rawPass, saltBytes);return encPass;}
- CredentialsDigest证书加密接口
public interface CredentialsDigest {/*** 散列生成摘要* @Title: digest * @param plainCredentials 密码明文* @param salt 混淆码数组* @return: String*/public String digest(String plainCredentials, byte[] salt);}
- CredentialsDigest证书加密抽象实现类
/*** Hash证书加密**/public abstract class AbstractHashCredentialsDigest implements CredentialsDigest {public static final int HASH_INTERATIONS = 1024;@Overridepublic String digest(String plainCredentials, byte[] salt) {if (StringUtils.isBlank(plainCredentials)) {return null;}byte[] hashPassword = digest(Cryptos.utf8encode(plainCredentials), salt);return Encodes.encodeHex(hashPassword);}/*** 需要实现加密转换* @Title: digest * @param input 输入字节数组* @param salt 混淆字节数组* @return: byte[]*/protected abstract byte[] digest(byte[] input, byte[] salt);}
- 不同加密方式(当前使用的是SHA1密码加密 )
(1) SHA1证书加密
public class Sha1CredentialsDigest extends AbstractHashCredentialsDigest {@Overrideprotected byte[] digest(byte[] input, byte[] salt) {return Digests.sha1(input, salt, HASH_INTERATIONS);}}
(2) SHA256证书加密
/*** SHA256证书加密*/public class Sha256CredentialsDigest extends AbstractHashCredentialsDigest implementsCredentialsDigest {@Overrideprotected byte[] digest(byte[] input, byte[] salt) {return Digests.sha256(input, salt, HASH_INTERATIONS);}}
(3) SHA512加密方式
/*** SHA512证书加密*/public class Sha512CredentialsDigest extends AbstractHashCredentialsDigest implementsCredentialsDigest {@Overrideprotected byte[] digest(byte[] input, byte[] salt) {return Digests.sha512(input, salt, HASH_INTERATIONS);}}
Input length must be multiple of 8 when decrypting with padded cipher相关推荐
- AES解密报错,Input length must be multiple of 16 when decrypting with padded cipher
项目场景:对登录用户名.密码前端加密,后端解密失败 问题描述 在做login登录页面的用户名和密码加密时,前端加密后端解密,但是抛出报错:Input length must be multiple o ...
- JAVA实现AES 解密报错Input length must be multiple of 16 when decrypting with padded cipher
加密代码 /*** 加密* * @param content 需要加密的内容* @param password 加密密码* @return*/public static byte[] encrypt( ...
- AES加密/解密报错,Input length must be multiple of 16 when decrypting with padded cipher
背景:需要存储一个类似密钥的字符串,密文存储,并要求能逆向解密出来. 问题描述:使用AES对该字符串进行加密后生成byte数组,使用new String()方法转为字符串后存储到数据库. 从数据库中取 ...
- javax.crypto.IllegalBlockSizeException: Input length not multiple of 8 bytes
使用java des加密算法时,出现javax.crypto.IllegalBlockSizeException: Input length not multiple of 8 bytes错误, 必须 ...
- android java.nio.charset.MalformedInputException: Input length = 1
java.nio.charset.MalformedInputException: Input length = 1 现象 What went wrong: Execution failed for ...
- 成功解决pypmml.base.PmmlError: (‘MalformedInputException‘, ‘Input length = 1‘)
成功解决raise PmmlError(je.getClass().getSimpleName(), je.getMessage()) pypmml.base.PmmlError: ('Malfor ...
- 【例4-3】利用数组,给定N个正整数数据(N<=100),查找最大值和最小值并输出。【输入输出样例】Input length (N<=100):(此处括号、冒号为英文符号,后面无空格;leng
[例4-3]利用数组,给定N个正整数数据(N<=100),查找最大值和最小值并输出. [输入输出样例] Input length (N<=100):(此处括号.冒号为英文符号,后面无空格: ...
- java.nio.charset.MalformedInputException: Input length = 2
问题: 项目在idea中编译运行没有问题,数据能入库.但是当java项目打包成jar包,运行该jar包后 下图蓝色的代码行报错: java.nio.charset.MalformedInputExce ...
- 解决AppCrawler自定义配置后报:java.nio.charset.MalformedInputException: Input length = 1的解决方法
解决方案: 自动生成demo.yml文件后,使用sublime打开,我这边默认是是gbk打开的,左下角如图: 所以更改文件格式,文件-设置文件编码-utf8 即可正常运行文件: java -jar a ...
- SpringBoot配置外部tomcat启动时发生Caused by: java.nio.charset.MalformedInputException: Input length = 1错误
错误来源 最近在编写springboot项目,需要配置外部tomcat.然而在配置好后启动测试时总是出现 org.yaml.snakeyaml.error.YAMLException: java.ni ...
最新文章
- JSON.parseObject(String str)与JSONObject.parseObject(String str)的区别
- 微博客之后有可能是“切客”
- 【pyradiomics学习】——影像组学特征
- 10月15日 2016中国开源年会期待您的参与
- OJ1066: 字符分类统计
- cogs62 [HNOI2004] 宠物收养所
- 【POJ3461】Oulipo(字符串Hash)
- 微信小程序框架--weui
- 火箭是这样连胜的(转载)
- 谈谈市场上常用语音芯片方案选型,录音芯片方案选型
- Switch中的参数
- 2020小迪培训(第21天 WEB 漏洞-文件上传之后端黑白名单绕过)
- tcp/ip 端口号有哪些
- Huawei SDN Certification 华为SDN网络认证产品EOX公告
- MacOS上使用ffmpeg利用显卡加速批量压缩视频
- Cognos BI交流群共享资料整理
- java小项目 ATM机(简易版)
- 电大计算机网考机考模拟试题答案,电大计算机网考机考模拟试题excel模拟题【呕心沥血整理、电大考试必过】.doc...
- 基于8086投票器仿真系统设计-毕设课设资料
- 地铁三号线 - 幸福的长发男子