V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
bwd1991
V2EX  ›  问与答

这个是怎么加密的啊?厂家说是 DES 加密,试了半天没搞出来

  •  
  •   bwd1991 · 2020-08-31 11:28:28 +08:00 · 2104 次点击
    这是一个创建于 1579 天前的主题,其中的信息可能已经有所发展或是发生改变。
    密文 35454f6c44397230456e566c36453064654b71726444736671373272305a4e41764c2f454134594d597154314930775356354361575576527771716276454b424466733534345045396c3837704577472f5479466646466948756936724f71364d66417353426d56366b7a434f4d6c6b2f384f735876615032553976756e2b797974735a43737543366a5a494f535453544e556343777a577846614171634d526b68776d597658546c3750746e6574384f39663771336c635836335655394e6f6f6c58706d6f613975703752416a334d616d73623943496948674c49752b545932526661645a334a7452726b465932737a3349365a767a6f7345444c42383937716d684f39756349576248597772537369466f4936756862383961706f61487174357a4e732b3849567a41796c7a732f41764e674854567a776953527643783766455a6c595a374c6c3732764862394b332f78564f6d62466d4b79313472664e443175356456626d6f32435653726c54776b4c4d4e324168334c2b4c576b6f776c45623652766476356133316f4d75394f5a543430515158567535426a3835516e58554b54666d56484e5964734a784764584f5552552f4634747946587a5446735a747654662b69662b50446a30385a65696b2f5348466f5868416e6139546b7052574f52315a74414b5a32796a6f72665450557251326b6545304a65576842574c4d4f61614d2b544b4d585267785536484f596b47364130676f59714b566e45356b6a4b51634f794c2f6466544b6274466e7a494a556758724649336b6442507845454a6248432b4e51676253384c6b5230367570346e564c4e2f776d47795a62535936476c46796c7878745436594377796c624866707331613659455449316e6b756d747330706a384a307067535a4d7535766c7a66572f776a66704a7249334a686c724372586372304a30705046512f4d64446e324269596d70336342342b7768704a41775a7a51366753424677777a7579306d534c556d476f50782b6c7a782f352f4e6978486e42307165475163523751746e684c4431686e304a383257625a354663687a6355784454415050434f686f316c7a63503359757542547a674a45684b37684a4235636279762f2f30472b494d7171542b64583659414f624d4e2b4875444f5364674d334d4c4a5847503675516b5342356d38537161557659316251646a6b516176622f726e3436532b58616c685679616473486164367a706a517270364350363761532b4c3679452b594c2f55436d69796c76617253344d74377a68696631666256334c394e2b462b574b30726f62723770524f6a64764730475a59356973444e677a666b6a7375787841364779552b7a4c317759626d7a464a71434e4976687268427841636c615a72632f694d2b4c4651625833465645467659356b744e462f743078624e5274734f6356677a464c4474477a6d376b6e305656337347414b486e4b6b4f316472734c724c4168793468316248394532424a7651745676597377736c76725259737653544666533059725559472b594d67596d426551366e793847695359444a4d7656744d4c744c545a6e36546146584a54467369654b7a3852513469343349736c3546337547655447426a5376355337666839446956774d755a776f756132652b734a334d50624e4e3455674539382f4b6630687671426c5166666c53592b56594242322b6b586563454e634c66646467574a4a716f4f682b37344d433650684a55526c684f586c4d7a702f79734370777a56794a754d484c39484e595979364f746f69364f63303878654b4a756a4c694e6d43695a3564324c765952786d30562b683674455a6b6e327a497179416a5a362b4d30746e6a50634744385876415335764853714d5244342b6d464f614b4c77434f2b6332504a3263516c44713970423146674e6674663579333237512b494d50416256594e31665972704474585a462b495a4a4830346f49624766503134642b6b4f37373575566c58774e3034444172636e50676c7576333347365861334c7138356c4f635972474a6b326e756d344b5a3656483971787679452b513839494b6e636375656e6b30523970522f59672f63503451584b4c6a37485a3165466b697a6f3938766a4e6f73396c62494c5661535979524866424462343247537351435737646d704a442b556a69443675515249426645674e4f47795a6d6e75596e63594d3559486d4b6f4c564262355754707a65416b3472385a7856546e54384b35467a375375394661314e54796b666a6b67386c536b627032364167546558556a686252304d414736306d4e4d664c71506731534b6c39723479733446304d4749624c764d516e2b306d49505166497a7870554b733854562b6b427761422b3437756665346a3439576b51476d737a65534d632f3770353070714b48655a65686130464533702b702f6665724e464d6c6851487267316b5a33363769536747476170784f4e7164347a635671384b4a4d384a376b37554767444457754a62575341696d34642b495a36693233413463352b45394f6c667a305a52544f636e734c6d41586b426870354569775a707259734d6255756d6668736e556655545873664e7053454c414f594b4865394342394a72773953774530426f33306f685a436e37454e6c4a2b756e415737416c7859334e41724863312f465779636c7134423648396d5445334b4349656b746a37564550417a52595347713456476e42796863616f32552b5467726b4f4d6e2b6471306a534f6149642b6e364b4a4f66764a717964696649703067466a395268392b32616e75746e795a364c68773864706a7562474639443448335044386c6a7254394d5132544159686f717879393655445a4e6a4376716e6173594e6b492b6a6757464159707338765875347a4b745a77716453475150645630484775694970452f674a643132356e445a576848655658623039345076474c64656b6465366473342f2f2b3051546e4a48432b49664e2b525131504c57554a44335643304264414a6a5467377a337466582b444f677a374634646e33696e41546e53767941346e3130776f422f7769666159554e6b367878596f75575831343736644a65696b7345376d5274735063516c5365795a354c346d6e706d493872417932444e5a4437357a6a394b62627a4c7a32784a307349717834764647456f7a57706650557470525144554a5639634c775731434376544c5638437978684f622b4d564555657a3068433270786934376e44756169555353624f77454c2b57796446624441374c2b3664346875354c4a76395444743656313672486e57496650567837575a48706649773332375930716562775261663350654c4a734b6c556e4b2b794c76717441734c6f35714862727a753066522f59417752614679756851706c39577072703869316e77654459716e613062375356314e5134415231386b315836636e4c704e6246314a2b6f386b52347835674253483043304c4a74424274614e6f5745486e5444566c7430624d772b4c73677a704b5773487a38737046565268545074486f75615a7268457036765645564c2f354b464843654272554d496936414e6c33746a6853516e5747746f71503343514c6f663333352b362f6a5465376c50722f466e6244775a744c39586962774251646a487256414979385279346b616c6b417730456558624258714e597373447a497344626f33566c3734424c486a644e734673306c6144482b4f317a41325a6449737157764b51596b6e75513362736b74654a7150745971454850534c7167707474366b4571344d4871422b3168326e7276676d56377374747233384c4231384f436c2f5354584f794b343372425141516e516e72415a49506e31775753616c2b644e66704175502f4c7658303761482f50474b556a6e53356d4d4c2b636578704c5065654b7076594148726b64543630647242387674634b365944574c3450305151352b685839445766676d4853704c414463356f63675772486570433233507377636d596355707a566d34476c643176467631594358486234344a366964683663647561656f3141367547736630696f7270684f3279386732686b6c6169537a6e77585036485a796c67735a453076774c7a79742b496c6d5a762f4e62394a5962465758486d306d43464f7278337172645063753169764f7465534d5233304f6d5164523244664e6e652f396c645445384949564c4970395847712b76497a306e7457424a426e4f34367a54416435752f51496b6d68345753424571374f4a6d4f6251683659784e42572f5476792b55524143394b354270585635782f4359544a32353843746477592f745177696c37763258316c4e7952534f65416e6f774d356741595469365256663668444938353631344d324e58326b58635639675158397078544b47696a5535306f75744b68514d453148546f5952772b444467336731663849346c4270325632666163316b5042722b2b79344b323666367532684e3852357743516b325a54475437397647794b2f6d326b5670626264694532336b36574f67756f7455433361554b463030665269687544346f6c574262316e5070306f4f4a5a484851706e52436f772b53496f32335273703876737573716a6c7447613066346438656d4b4e37453332776e534363346f3861524a6453655839373534654975314c3878646e624e556d6c6c75484e6732324e64363441564e59672f5274755368505339444e39503837702b496d5649676154586b5132525857655a75626b2b4b6869456d7570333268794d2f626457756e7a4a2f6150334c643552676338324d35354c3875614c544b724a717763343154654f49353278644a5a4859365a4563395950703839502f417153574976592f4761536c4551673141435466553548636c3431656f6544304e2b784833507257746e43665a423572464d777459424a5a6e5932426656615a314a4d7358646344356b33724c6142744c7949627a356751436c6d6630574763474e4d4751636b686d3453516d66382b4e705779303169516448394d4e4f4774426c4343612f506853336349645a73594841302b576e7a79482f4f4e4b5a7672593248574877327a344f4c312b70322b492f3842385a66706c34494c705352316e50364b55354370584658722b706e395179584178496771564742434375697a513559594941646d684548464a6d4566546c52344b51464d55483463707672336959504b567732395a5a795838644f5970652f505645705267693162314e7145385a65455241584e6a2b59333550464c63364c433658674363557839637a5a6835452b644b5a525458387041385575466c62505a6c4154414f47794f596839464935626d6b6d352b6c475667423531494d56767030394961395634554131504c496e7152584a673450667a394246504b4458734a7a5a58363567314a3547645a7276562b6341774447695035536c6c556643754b4d77423148665155685a6e5474386c2f6e584639735848676f586b43334c504e45706643625934692f6b653248315667477a336b58714c642f4a7679333856536942494c634435754679556a6330625844494769704f2b5638362b796e2f6d4a6a486973696374796c337a6f6e676a73556f726959646a4b37744e445563365761526e6e736352744e4e68376258684169694744586877727166787457496e466e616c69554350686d4d47316e5034656445435438545852366b477856754d6675464d467856586c4f4d304a4b615062693145356f33357845325675394442552b704552755235673078374477787065584d52344f56564b4c3372505775716c48696b59425a63794a507a7071667566797a6c484368436e2f455349416e6d56427730715363474e3173634234714745417265657a43495631717268473761556b5763395672657131735a79564f565741687133766f42723378357a364b616c742b6d3978705548623074636630766e38324249707a504f4e3833592b6d3851636f576745723879574c333871796d4e5a795877436546454b3533485779736138494f36416478584b49565255644670357066546a2b6d4a6231653834693762526f5138593963424d69307274484b376b596c365a674b4d6f552f44432b646d546b564f57714e395173303239633935435963695242566b504a424a43624254326a595366795046635a594e634c596b615855516e79366e7743317652546e5243656c4257316179393053636841306d35424b4d70467932724b586c4c7353396741344b2b67795442346c7733484d6d6146504c7464657a6c3451694e2b497847702b533553383862686364484d715042644b324f4e4747774a574b47562f77724b52374165507375697a362b4151484f76774c75335047486b50726d646430495a6b72732b686558444874334a4a657662414a733637423030745a6b736c3373564a7046494b78434f2b6e6557434a366c725837585150466a476a2b574649484b35747347434f37617a3451386a394659614a7757704d58734662672f673569756f3253436541796e74354148506444707578354a67684249596442492b314b526b616c5a5155512b43614e39562f4d7858542b51476347646348344c4c797164355a346c61325347744b6a6f4a636a564463413457764f37445233546a38394f3667644d6b4163667544555330442b444c704c592b52392b6a6a6b736c5a2f73356a696b3661746135682b7a565a334c47556e4c384c73664a6672347157597878564777702f454a45655a654c7a3770454a612f655767327243686d5a5536456757516954386648673237677a72386b763355346770366a5258766a7a73664542303832664b4f656a57643551754d4c517a4e69397443506b6346334a4c3770396c44695968454c6652457234383869614c572f3670344155322b6e48644e4c46772f2f6857506e4a674b4a6544696c354f4133567a75702b6c6d48696a2f716636713732447a666e6464483042436241614162533165792b4f524a4f5742736b2f4254653963724b45697565734842315963674d3533504e653634722b37324374535761483237654b6564334877704c6f3344554e6c35463342704c54685a706a585657645273397076304f5a7864544d707a37636c68496c4d777338464648326330456e387a4a4c7a36665871682b49777a3771647a393863505378702b414c7334664c556f486c4d5238734a376b4c4a766f307a5738684e5479797751583277636e6d4a63366a42684668444c5331514b53693250797362614c6d7545674477716a46464a7a616b35416b363174706358504e41365073575939654f77496458647156336e50726c4e56506c5562674d536a6f677750784d6b2b62324741747655345a4a513442624e4a702f742f6a4e47545039496576414f6761655076582f4e4b4974766b6c795171396832596e4a376238596975427861316d63444e6961735a50314748674651796c2f64667a586362545157372f4d77326d63326a4b4777644d50316b5734446b617576497265705945487856626e52304f343636657253767758646a776a6e79615a79655237504b6e4a55544643614f646936693163776d547a64617a31464879584d656b35434553447757727131477a3157463648432b35526271615176723362385172504b525355596d694832676f7171717874716761634537744f393175636367716a6d566e75503662644958366e3130684f6334794e415639306a4c45577762564e5639336a6165696e35386d59506c32516d613361716579366d42596e43702b796c6a32397561696a4d5950692b773559775a536a4e504f35366e347968683345524433464d5033526e4a5a6c6357615a646a7979454542442f34464e6e4867344161367278456b346f53746e2f592b6266477137364f714a4a42503055496d68302b622b53653777306c47424e764d7550645761714937696e5034436b44524e2f37436b723664726443307439674f673d

    秘钥 lsl123456
    8 条回复    2020-09-01 09:53:35 +08:00
    wakzz
        1
    wakzz  
       2020-08-31 11:42:31 +08:00   ❤️ 1
    这年头还用 DES,这算法已经标记为不安全了。
    只有秘钥没有初始向量的话,那估计是 DES-ECB 加密算法了。而且 DES 的合法秘钥长度是 8 字节,你这个 9 字节的秘钥肯定是不对的。
    让厂家给个代码 demo,或者直接给个 OpenSSL 命令 demo 。怀疑厂家提供的密钥并不是真正的密钥,还需要其他算法例如 JDK 的 SecureRandom 把初始密钥计算成参与加密算法的真正 8 字节长度密钥。
    bwd1991
        2
    bwd1991  
    OP
       2020-08-31 14:01:49 +08:00
    @wakzz 我找了几个方法都不行 厂家就个实施让我自己试 我找了几个在线的都是生成带特殊符号的 他这个是怎么做的啊 原文就是个 json 有思路吗
    javashell
        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"}]}
    bwd1991
        4
    bwd1991  
    OP
       2020-08-31 16:03:23 +08:00
    @javashell 这个是怎么加密的啊 能给段代码吗?
    javashell
        5
    javashell  
       2020-08-31 16:10:31 +08:00 via Android
    @bwd1991 des 的 cbc 模式,密钥和向量都是同一个,http://tool.chacuo.net/cryptdes 就可以解
    bwd1991
        6
    bwd1991  
    OP
       2020-08-31 16:27:40 +08:00
    @javashell 我试了下只出现一个 j 啊 还需要配置什么吗 ? DES 加密模式: CBC
    填充: zeropadding
    密码: lsl123456
    偏移量: lsl123456
    输出: base64 字符集:gb2312
    javashell
        7
    javashell  
       2020-08-31 16:53:20 +08:00 via Android
    先把密文 hex 转成 strings 然后我填充选的是 pkcs5
    aurthur
        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]( )
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   4816 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 05:39 · PVG 13:39 · LAX 21:39 · JFK 00:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.