ios - CryptoSwift + CryptoJS Swift -


i need here decrypting server response encrypted cryptojs.

i use cryptoswift decrypt response.

here sample of server response data get.

{\"ct\":\"twqy1xihfw+shg9l8onyuah8xwbgy7yhef/ibb6jkkmx+ndq2u78553/0hxlxvknp6xsagc0zg+2avkccshlkrjrsilvgzmdcklparbzia3z2drozegrkrctin2fk4pkn0xiidnbeth0umdinurdfxoeirqlffobgqdz5virdw9tvhl3ftz169ooeg1dutag0bq5qu4tp1k4vstd78kwr4c2a4qypj1baqrjrsabdahhbvjrgiosy5d30h10e9re9iegdwsfuoxw0+2n5nhfswpuwadv45t6funz5ptc/l1njvpti2czghiw4vl8px3huzpefpje9uunupr2e8/vhqt8hx+jjt0looszhcuj4ewv2l6teawxk5i1mnz7xmkvrayut7jyu2ob8ite+zjaatiokhhri1heu9wmeves6sdp2jdqflm6rb2v3vnhtrqwgqlcg+rnpsgg0zqumtoko6mrn/vjadmtpyjbgp1o5ickrr5vvsvyi3aejwrjkitppy/hvk8oa8ovmzjuwsncpejflww8adegawrbzzyguszsooc8/o5objvspzqrohtffao8sbms2ovjes5wgycbew33i1ka8d1ejg+ncyr7h/rojwpy8ynbwc0qbn9qkbnfrdxlqvrr8g6chrrezgvvplx8aypmfsahzf/kppax0ypmf1v29rjwkbcworslisa7uulkzzhvdrgx3pel+mpi2bqb9myajhhrkjat2t6k8ffxkzvmckrulllm/k9ax3duqnmubj6schblg+cl3vfeqzzwj1mjw09cklgfcoi06bebkp9apqbrkrybosunlam6cnm7/tqitgd//fx88bgqnl0wc8gygkst+nvxc+vwcnis88pdczht4ey5ee3wy8lokceuzoc7t8//qp72tmurfzpulzn45lqmz2z83fd115joniv/hjeoqgx88ogtpcs6q3mp7kd5xxektq6hott5wfzxetdgsezffizvrzhts05hbtjvnd5n10lyisfiegd9ktbtlkso2pqidemt3xi2m/jp9+tz9kbkus2vqjb8hfh27f8/mrlnhjboqgjmhbswvq9tvztfekbb090hg3aqz3kbzlmfcoj6kco1ehakhixgojfkx93nii2mfjfbsugctr/sl/ueshjyquqblsgaqrsqr7dpgo55/at055y+4v1lxlkodtq6gnxpkzyusmltlsmxgmsygkbwolvybcz8na7pnnlr3ym/ehgucfmlhtduaq07hitahsz/b6f6zsymbero8fbrk8ds9gi/3/kmhxgq+0ldect/f2hab/yncnsjhbilomx+28vahbzbekkzuk94uxbvxuurs573s6j6yzmcbnb2cc2yflw4lanzxi8jt8mrgzhbxsdquqez58k0jndyzpljm0m7mqj7i5hjjiuyq3wtkdeffih3zomnvmr9pgiwbq9ngjwub3jglynjx1nx0xt+x8hnfytd7rkhimi8ljc4b+fcv7k4sakx3bzcsq54sazfryqdokbeg0y+cxxxoqjimmk9knjbyfcyyq+xgtdagyd+3ruk3xlhjozl8jiowhvhtse/mvld8b8jbs6ffjdeb1zdddfbhrbkdiepvnhu/fuodb+1km59cmoze0o9s22bzas8pzv9fv0oeesqdsszukzr4vgrlwj5z/eyfrwjodqfkwekl3ewj3paestnvc8ew1fogtanrmo9gytiuooweep9kvjef0yftmtj6jx/jzjsqpsz6yevt4egwes3ky817wfmya2r/8ivlrl5be5axzw7jikjfhztnsnlts58dcuovqmtngrdbaxipxcdfqdw4j9rx03cnssuvf40rysgx7juwxolz/hs/u18mvy2e7+mnuo7hlnamhflglrlt7uf9fnbyzhgbatfawug9wy05wmbn3n2ghbmqmacwfxvmzvtxog8dijhobw6suv/3iqbkhpibafpp9mgeg9uoccnreh0tc4wdbqycbfbedewyf+2utopxhdqtrszamv4sh0iigru89lkxcqdkuklebkqsa9gd9fin0moa3h/fcppchdcycsvxovdp6akmnu6r9eewuvybdke8liwklsvb7gsweri3m4l3dear7hho2nqbmzq03rrgg5+bc4utasdhwu0bvv+zh9kjtk2as1xjcoeusyos6lua4dkx2uhkpe5jhb6zcamp8zpfjy4tuwlzkszuibi92z3ffeeytacxd9xmor2jgn2rzaumbdgqwxq0v3hh6ttdguaeltb/ewgnnxodgtrfui624afi6nz2brt5vhdmckhbf/arw8now9h2ek8s0vjq0a1435c30g0wqc73jrkw32jayo8ivg0vnszwf385sdax3jnj0l8l4btqh8z/cuaiqulamtibq2opanpninzroe+z5/reo0xmftit7vdduq1hprhty/n3eowe1chhlbdvom6toxh2d51f40ej0/qs+ch4dbrqytyxehkljb+ha+7epsjqmudsrqhxogukcnuh/vm425zpuxige4e+kdslauwtx1u1/wagvywjyj12oez84xsxvf0kjs1ncfvnkhb3wejjrbsrbbvcbkp4zzsmtzcgfrzugqhtz2lhzftduaqya/txjaf8dbdq+hlf+8rpul1riaczqoqdqkonymh2wa9utwlwtympvjodlpeo5ml+yxqx9ich3yycr8ssjgckbmen+ylyduowldfic8ngnlcprpdqxrm0adtwxadibg4ywigaxozxcqekiuxk0nuossw9z6tcb6yxdpzjdrqeoc2i2ky82ysirlhputspqycpaf4b8gbsubciqtflyhebiz50t3gk4gns/2hnshgdzjphjbvqk+gzetau9t0jmbwbkuhq07r0lvm8zn474yhvzyixobuuzjkpgwpk+fvbep1qxotp4ekbsdgu0pcno/y7d3g4r26qtwmywvnfkfaagjxawwxkqbcdsjzxnkogg/uekcahrswuq9qaejhu1dl+m9oowa7igwlxtupht0+1fgbn14=\",\"iv\":\"d6d6bd8ee407bc25a7b23d8d36b7bce9\",\"s\":\"b8e72892c801c87c\"}"}

simple string parsing clears encrypted string , gives me following data:

let iv = "d6d6bd8ee407bc25a7b23d8d36b7bce9"  let salt = "b8e72892c801c87c" 

and key formend other data

let key = "8aa1ec1e6948b481d1ee450c94ffb2edc774877325df4d05aca2e5827497ed33" 

here peace of code use decrypt response:

// transforming key [uint8]     let keychars = array(key.characters)     let keybytes = 0.stride(to: keychars.count, by: 2).map {         uint8(string(keychars[$0 ..< $0+2]), radix: 16) ?? 0     }      // transforming iv [uint8]     let ivchars = array(iv.characters)     let ivbytes = 0.stride(to: ivchars.count, by: 2).map {         uint8(string(ivchars[$0 ..< $0+2]), radix: 16) ?? 0     }      // transforming encrypteddata [uint8]     let messagedata = encrypted.datafromhexadecimalstring()     let bytearray = messagedata!.arrayofbytes()       {         let decryptedbytes: [uint8] = try aes(key: keybytes, iv: ivbytes, blockmode: .cfb).decrypt(bytearray)         let data = nsdata.withbytes(decryptedbytes)         let decrypted = data.base64encodedstringwithoptions([])         let json = try nsjsonserialization.jsonobjectwithdata(data, options: nsjsonreadingoptions())         print("decrypted = \(json)")     } catch {         print("error = \(error)")     } 

what ever either error = decrypt or base64 string not decode json suppose to.

p.s.: did try cryptojs.swift result "undefined"

upd

sample project how data encrypted on end:

cryptojs.aes.encrypt(json.stringify(options.params), key, { format: jsonformatter }).tostring() 

this how data decrypted on end:

json.parse(cryptojs.enc.utf8.stringify(cryptojs.aes.decrypt(raw, key, { format: jsonformatter }))) 

i tried to similar in sample project reason did not work me.

upd2

update end

// nodejs import var node_cryptojs   = require('node-cryptojs-aes'); var cryptojs        = node_cryptojs.cryptojs; var jsonformatter   = node_cryptojs.jsonformatter; // data encrypt , encryption key var data            = {'hello':'world'}; var key             = '8aa1ec1e6948b481d1ee450c94ffb2edc774877325df4d05aca2e5827497ed33'; // encryption of data var encrypted       = cryptojs.aes.encry  var decrypted       = json.parse(cryptojs.enc.utf8.stringify(cryptojs.aes.decrypt(encrypted, key, { format: jsonformatter }))) 

upd3

no, name similar api different. used npmjs.com/package/node-cryptojs-aes on server-side (encryption+ decryption) , code.google.com/archive/p/crypto-js client-side on our site (also encryption+decryption)

sample of encrypted data

{"_id":"5687ad129b65920a00b56a9b","type":"user","created":"2016-01-02t10:57:22.851z","uuid":"d9df3412cee97ec1d0a8c547f73e4bb6","secret":"307a14f6ffc667c7941e6263edca4149","profile":{"lastname":"mmm","gender":"male","firstname":"mmm","email":"mmm@mmm.mmm","dob":"1993-10-31t00:00:00.000+0200"},"avatar":{"large":"https://graph.facebook.com/v2.4/1122734811071660/picture?width=120&height=120"},"location":{"country":{"filename":"greece","code":"gr","continent":"europe","name":"greece"},"state":{"id":"aitolia kai akarnania","country":"gr","name":"aitolia kai akarnania"}},"auth":{"facebook":{"userid":"1122734811071660"}},"notifications":{"new_window":{"sms":false,"email":true,"push":false},"new_live":{"sms":false,"email":true,"push":false},"new_premium":{"sms":true,"email":true,"push":false},"reminder":{"sms":true,"email":true,"push":false},"new_arcade":{"sms":true,"email":true,"push":false},"ranking":{"sms":false,"email":true,"push":false}},"metas":{},"stats":{"game":{"time":{"total":1084452,"maze":{"mean":180436,"stdev":423,"min":180013,"max":180859,"sum":360872},"wordsearch":{"mean":111639.5,"stdev":68379.5,"min":43260,"max":180019,"sum":223279},"trivia":{"mean":22410,"stdev":0,"min":22410,"max":22410,"sum":22410},"brokenword":{"mean":40399,"stdev":0,"min":40399,"max":40399,"sum":40399},"imagelabel":{"mean":38349.5,"stdev":22808.5,"min":15541,"max":61158,"sum":76699},"scramble":{"mean":180174,"stdev":0,"min":180174,"max":180174,"sum":180174},"sort":{"mean":180619,"stdev":0,"min":180619,"max":180619,"sum":180619}},"score":{"total":4500,"maze":{"mean":null,"stdev":null,"min":null,"max":null,"sum":0},"wordsearch":{"mean":1000,"stdev":0,"min":1000,"max":1000,"sum":1000},"trivia":{"mean":800,"stdev":0,"min":800,"max":800,"sum":800},"brokenword":{"mean":800,"stdev":0,"min":800,"max":800,"sum":800},"imagelabel":{"mean":950,"stdev":50,"min":900,"max":1000,"sum":1900},"scramble":{"mean":null,"stdev":null,"min":null,"max":null,"sum":0},"sort":{"mean":null,"stdev":null,"min":null,"max":null,"sum":0}}},"positions":{"position":{"avg":0}},"played":{"window":1,"total":232,"live":120,"arcade":101,"live-duplicate":10}},"credits":487,"utm":"false","perms":{"root":true},"undefined":null,"value":{"credits":520,"usd":52,"bought":3},"premium":true}


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo