Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sm4-密钥为16位字符串 #26

Open
Mangohah opened this issue Jul 13, 2022 · 4 comments
Open

sm4-密钥为16位字符串 #26

Mangohah opened this issue Jul 13, 2022 · 4 comments

Comments

@Mangohah
Copy link

请问为什么key为16位字符串时报非法?
在线加/解密工具(https://the-x.cn/cryptography/Sm4.aspx)可以为16位字符串。
image

@JuneAndGreen
Copy link
Contributor

image

image

目前的实现中,hex 串转字节数组后会有个长度判断

@wsm661
Copy link

wsm661 commented Oct 21, 2022

扒取源码,发现https://the-x.cn/cryptography/Sm4.aspx,生成16位长度的数组时方式不一样,他们是类似CryptoJS.enc.Utf8.parse(key)生成,导致两遍加密出来的结果会有差距。

目前这个插件,如果在sm.js 的1740行,重新设置key为一样的16位数组,最后加密串会是一样的。

如果不修改sm.js,需要在加签前,对key做兼容处理。

@wsm661
Copy link

wsm661 commented Oct 21, 2022

提前把16位的key,转成ascll码的16个长度的数组,即可。

@GuoPeng361
Copy link

需要将16位字符长度的key转成ascll码的16个长度的数组,如JeF8U9wHFOMfs2Y8,转化成 [74, 101, 70, 56, 85, 57, 119, 72, 70, 79, 77, 102, 115, 50, 89, 56]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants