当前位置:网站首页>Input length must be multiple of 8 when decrypting with padded cipher
Input length must be multiple of 8 when decrypting with padded cipher
2022-07-31 05:08:00 【小果子^_^】
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接口实现类
@Override
public 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;
@Override
public 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 {
@Override
protected byte[] digest(byte[] input, byte[] salt) {
return Digests.sha1(input, salt, HASH_INTERATIONS);
}
}
(2) SHA256证书加密
/** * SHA256证书加密 */
public class Sha256CredentialsDigest extends AbstractHashCredentialsDigest implements
CredentialsDigest {
@Override
protected byte[] digest(byte[] input, byte[] salt) {
return Digests.sha256(input, salt, HASH_INTERATIONS);
}
}
(3) SHA512加密方式
/** * SHA512证书加密 */
public class Sha512CredentialsDigest extends AbstractHashCredentialsDigest implements
CredentialsDigest {
@Override
protected byte[] digest(byte[] input, byte[] salt) {
return Digests.sha512(input, salt, HASH_INTERATIONS);
}
}
边栏推荐
- STM32——DMA
- MySQL优化:从十几秒优化到三百毫秒
- View source and switch mirrors in two ways: npm and nrm
- MySQL常见面试题汇总(建议收藏!!!)
- CentOS7 install MySQL graphic detailed tutorial
- MySQL transaction isolation level, rounding
- wx.miniProgram.navigateTo在web-view中跳回小程序并传参
- Multiple table query of sql statement
- MySQL optimization: from ten seconds to three hundred milliseconds
- Puzzle Game Level Design: Reverse Method--Explaining Puzzle Game Level Design
猜你喜欢
![[debug highlights] Expected input batch_size (1) to match target batch_size (0)](/img/b3/ff6ccc3cd307befad3bd07a9f4a956.png)
[debug highlights] Expected input batch_size (1) to match target batch_size (0)
![2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。](/img/7f/130a9b733855a2bab07d26ffda2c49.png)
2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。

MySQL_关于JSON数据的查询

Go language study notes - dealing with timeout problems - Context usage | Go language from scratch

Doris学习笔记之监控

12个MySQL慢查询的原因分析

Create componentized development based on ILRuntime hot update
【一起学Rust】Rust学习前准备——注释和格式化输出

MySQL forgot password

MySQL database backup
随机推荐
【py脚本】批量二值化处理图像
打造基于ILRuntime热更新的组件化开发
Sql解析转换之JSqlParse完整介绍
MySQL优化之慢日志查询
MySQL忘记密码怎么办
STM32 - DMA
C Implementation of Simple Network File Copy
View source and switch mirrors in two ways: npm and nrm
matlab simulink欠驱动水面船舶航迹自抗扰控制研究
MySQL事务(transaction) (有这篇就足够了..)
MySQL8.0.26安装配置教程(windows 64位)
Temporal客户端模型
MySQL-Explain详解
MySQL optimization slow log query
MySQL8.0安装教程,在Linux环境安装MySQL8.0教程,最新教程 超详细
【C语言】操作符详解
Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
.NET-9. A mess of theoretical notes (concepts, ideas)
如何将项目部署到服务器上(全套教程)
The Vue project connects to the MySQL database through node and implements addition, deletion, modification and query operations