1
wakzz 2020-08-31 11:42:31 +08:00 1
这年头还用 DES,这算法已经标记为不安全了。
只有秘钥没有初始向量的话,那估计是 DES-ECB 加密算法了。而且 DES 的合法秘钥长度是 8 字节,你这个 9 字节的秘钥肯定是不对的。 让厂家给个代码 demo,或者直接给个 OpenSSL 命令 demo 。怀疑厂家提供的密钥并不是真正的密钥,还需要其他算法例如 JDK 的 SecureRandom 把初始密钥计算成参与加密算法的真正 8 字节长度密钥。 |
2
bwd1991 OP @wakzz 我找了几个方法都不行 厂家就个实施让我自己试 我找了几个在线的都是生成带特殊符号的 他这个是怎么做的啊 原文就是个 json 有思路吗
|
3
javashell 2020-08-31 14:15:32 +08:00 via Android 1
{"prescription":[{"delnum":"","hospital_name":"兰溪市中医院","pspnum":"1001373570","name":"胡美珍","sex":2,"age":64,"phone":"15167972589","address":"浙江省兰溪市桥头大丰大报亭(大丰大边上)","department":"","inpatientarea":"","Ward":"","Sickbed":"","diagresult":"结缔组织病、无并发症","dose":7,"takenum":2,"getdrugtime":"dhySYSTEM","getdrugnum":0,"decscheme":21,"oncetime":"dhySYSTEM","twicetime":"dhySYSTEM","packagenum":200,"dotime":"dhySYSTEM","doperson":"X488","dtbcompany":"胡美珍","dtbaddress":"浙江省兰溪市桥头大丰大报亭(大丰大边上)","dtbphone":"15167972589","dtbtype":4,"soakwater":"dhySYSTEM","soaktime":30,"labelnum":0,"remark":"","doctor":"G014","footnote":"","ordertime":"dhySYSTEM","curstate":"","decmothed":"dhySYSTEM","takeway":"dhySYSTEM","takemethod":"内服","remarkA":"","remarkB":"","drug_count":"18","isDaijian":"dhySYSTEM","payment":"","Yizhu":"","money":"","outpatientNumber":"B25760375","outpatientIndex":"12448144","ptype":"dhySYSTEM"}],"drug":[{"drugnum":"44910","drugname":"郁金 1g","drugposition":"1g","drugallnum":10,"drugdescription":"","tienum":2,"drugweight":70,"description":"","retailprice":"0.0983","unit":"g"},{"drugnum":"43808","drugname":"炒白芍 1g","drugposition":"1g","drugallnum":10,"drugdescription":"","tienum":2,"drugweight":70,"description":"","retailprice":"0.1243","unit":"g"},{"drugnum":"45585","drugname":"熟地 1g","drugposition":"1g","drugallnum":10,"drugdescription":"","tienum":2,"drugweight":70,"description":"","retailprice":"0.085","unit":"g"},{"drugnum":"45344","drugname":"山药(复方) 1g","drugposition":"1g","drugallnum":12,"drugdescription":"","tienum":2,"drugweight":84,"description":"","retailprice":"0.061","unit":"g"},{"drugnum":"44854","drugname":"枸杞子(复方) 1g","drugposition":"1g","drugallnum":10,"drugdescription":"","tienum":2,"drugweight":70,"description":"","retailprice":"0.2204","unit":"g"},{"drugnum":"44806","drugname":"覆盆子 1g","drugposition":"1g","drugallnum":6,"drugdescription":"","tienum":2,"drugweight":42,"description":"","retailprice":"0.3591","unit":"g"},{"drugnum":"45547","drugname":"太子参 1g","drugposition":"1g","drugallnum":12,"drugdescription":"","tienum":2,"drugweight":84,"description":"","retailprice":"0.351","unit":"g"},{"drugnum":"45763","drugname":"蜜黄芪(复方) 1g","drugposition":"1g","drugallnum":12,"drugdescription":"","tienum":2,"drugweight":84,"description":"","retailprice":"0.1161","unit":"g"},{"drugnum":"45757","drugname":"蜜甘草(复方) 1g","drugposition":"1g","drugallnum":6,"drugdescription":"","tienum":2,"drugweight":42,"description":"","retailprice":"0.1215","unit":"g"},{"drugnum":"45805","drugname":"桑椹(复方) 1g","drugposition":"1g","drugallnum":10,"drugdescription":"","tienum":2,"drugweight":70,"description":"","retailprice":"0.223","unit":"g"},{"drugnum":"44980","drugname":"盐杜仲 1g","drugposition":"1g","drugallnum":10,"drugdescription":"","tienum":2,"drugweight":70,"description":"","retailprice":"0.072","unit":"g"},{"drugnum":"45677","drugname":"路路通 1g","drugposition":"1g","drugallnum":10,"drugdescription":"","tienum":2,"drugweight":70,"description":"","retailprice":"0.0361","unit":"g"},{"drugnum":"45665","drugname":"鹿角片 1g","drugposition":"1g","drugallnum":6,"drugdescription":"","tienum":2,"drugweight":42,"description":"","retailprice":"1.08","unit":"g"},{"drugnum":"45405","drugname":"仙灵脾 1g","drugposition":"1g","drugallnum":10,"drugdescription":"","tienum":2,"drugweight":70,"description":"","retailprice":"0.1307","unit":"g"},{"drugnum":"45735","drugname":"玫瑰花 1g","drugposition":"1g","drugallnum":10,"drugdescription":"","tienum":2,"drugweight":70,"description":"","retailprice":"0.1978","unit":"g"},{"drugnum":"45793","drugname":"砂仁(复方) 1g","drugposition":"1g","drugallnum":4,"drugdescription":"后下","tienum":2,"drugweight":28,"description":"","retailprice":"1.215","unit":"g"},{"drugnum":"45437","drugname":"五味子 1g","drugposition":"1g","drugallnum":8,"drugdescription":"","tienum":2,"drugweight":56,"description":"","retailprice":"0.7493","unit":"g"},{"drugnum":"43834","drugname":"车前子(包) 1g","drugposition":"1g","drugallnum":12,"drugdescription":"包煎","tienum":2,"drugweight":84,"description":"","retailprice":"0.182","unit":"g"}]}
|
5
javashell 2020-08-31 16:10:31 +08:00 via Android
@bwd1991 des 的 cbc 模式,密钥和向量都是同一个,http://tool.chacuo.net/cryptdes 就可以解
|
6
bwd1991 OP @javashell 我试了下只出现一个 j 啊 还需要配置什么吗 ? DES 加密模式: CBC
填充: zeropadding 密码: lsl123456 偏移量: lsl123456 输出: base64 字符集:gb2312 |
7
javashell 2020-08-31 16:53:20 +08:00 via Android
先把密文 hex 转成 strings 然后我填充选的是 pkcs5
|
8
aurthur 2020-09-01 09:53:35 +08:00
理论解释:
- 密码:确认加密模式是 DES-CBC 的话,那么你的密钥长度肯定不对,只需要 8 位,尝试去掉最后一位好了(很多加密算法实现时密钥长度超出默认只用前 8 位,并不报错),所以 **密码 = lsl12345** - 偏移量:这里厂家未告知你偏移量,默认就用密码(这也是算法实现时的毛病),所以 **偏移量 = lsl12345** - 再来确认密文组:对于 DES-CBC 加密模式来说,数据加密后模式是多组 64 位长度的密文块,这时候你的密文要存在数据库里一般会把它转成字符串存进去。 - 这时候 密文块 到 字符串 一般使用两种方式,要么 toHex,要么 toBase64 - 这里看密文是 hex 模式,我尝试了一下,直接反解是失败的 - 根据上面老哥提示,我将密文先从 hexToString 尝试了一下,得到一串字符串,一看就是 Base64 自符 - 故知:**厂家是将密文组 先 toBase64,再 toHex,这时候我们依次先 hexToString 一下,再将 Base64ToByte 一下得到密文组** - 填充模式:这里选 **pkcs5**,其实用的是标准算法是无所谓的 - 解密即可得到你要的数据了 代码实战(我这里是 Golang ),你自己根据上面理论套一下就可以了 ![Imgur]( ) 你也可以使用在线工具试一下: https://www.ssleye.com/des_cipher.html ![Imgur]( ) |