Ruby string splitting -
i have long string follows:
miiepaibaakcaqeayue3zaacnx50xrvh6csl05yjyxzrpmkfqlkfn4qfrbbkgogfy7nlfniccchg1kux8+bi5txoovf28qa7drizrz6hnyrxvmjkklhkczmghapefss3swk2knw6bzvqmo20fidib/fudzrsn0e9uixlowfcfodffs3h4bhkkeagkw8swso6dwjhoezecxtn3u7z6qnybbjzxfy2h0o8cerdhhisirjj9bofvyx4drkuq98x16ypwigutxjfijn5xrwj1ipybabcsxfdvque06c/cs47hguxho2guwynw9u08yzrpho+cbse8w5/cq3vzrybox/ladrkmjp76bx0nxv/3widaqabaoibaqc7wfzfyexhmenbyfzdgcnl/nuzw3duy057jfynzwttuygu4yyyj6mo0cc8rcjyud+ksva15j8juexgloysrqfrv3wpbn5boojkyxuijaksscnr2gnpyixjm+q2ebe7jssquejt6vtmgfx/748okzekaocflytvhktzned5s6hdf1sluhstgybnyh6phbid+ssdjqrt7ys1s3eflaxjijeaeltpi4djvrbjbvshhl9btzrrqh3sik7bddheq7pu6/y63zepc7z6pdeb+sx8c4dktrpriuae1eooh7ifk1ddf97wjoza3vgeqfspy1ipms1xp+668z0vrs6yfeuwltuhaogbao8ymjuyyo59dh/c+y/5g+bsgqr2gz5cflltfq4+v3vpbe4zezd5l0/vse/1qkeilwwhxrc5t3ksiyseylmhlwskgbofh7mdaw0wcottxgtawiqzmwkae8cncx8jnw9a3bq7j+e0im+bee0nxjhmfcoqieo+yjasvhucwi0f+vmdaogbaneddo6khbopu69i5uih5tfnkllqoovdxygembfawjnmec5em6uhg+ygadhr7ont5om5k4wk3uif3vnqspaq0md6gg514szyatukwy3+bgqgpfv8yohsogdc8i58qvxpurse07pxah+n7krtn3i0nhatlkj4okaucnolf0nocpsraogalwupaeycfcjibqgr/1nlrtpcjxshfwbkx3gtdeu5r21xcsqadl9dl5bxe0bt0nmdhmmldevzn55hdaqw3wfi9fjby0r6wegbmmvvb8r0wucpugdkpti2hbqtu6u67/jgpnkvodmsn4y3rwgvk/64o72puv7rrg+z5j/xdqlmnlkcgyagqmqj3pw6yn/ilet3idr6hsxpi3brmqyqjdhsp5dtam9mjm94hquk4unmlnklfzquhvemotxjscasksupqonvqna0emrjuivfprfc4+qty3vnivixxcrv55b9itfvk07ejhkrx87qmygyb52oeyzibp/lyqid7alj5f0arbgedwkbgqddonxscchqqlpafo9xlvltu2jscwcjat4dh8xhfdkgtyg+acrb75+pvgw7jpg3311n8suuf2eq3rwocdvzuhd+tlunmqrw7ifpkhtl1po6ka/+g6xwh00zkxl5o6abmq/fzw6/yk5yx5prxuwhlycn6zvgjnenwmzkhvtawthhfw==
i need de-concatenate/split block looks this. i.e. correct format used x509 certificate.
-----begin certificate----- miigntccbr2gawibagikywygxqabaaacazanbgkqhkig9w0baqufadbdmrmweqyk czimizpylgqbgrydy29tmrcwfqykczimizpylgqbgryhy2puzgvtbzetmbega1ue axmky2puzgvtby1dqtaefw0xmza0mtixnjm4mtvafw0xndazmdgxmjm0ndhamhwx czajbgnvbaytakdcmriweaydvqqiewlczxjrc2hpcmuxedaobgnvbactb1nfifrl yw0xdzanbgnvbaotblzlbmfmaterma8ga1ueaxmibmv3y2vyddqxizahbgkqhkig 9w0bcqewfgphc29ulmjvdxjuzub2zwquy29tmiibijanbgkqhkig9w0baqefaaoc aq8amiibcgkcaqeav+ilegq1b81joosgpysk+fo4+wqxjk4dygwbc/mrw5ju2shq mjkpab8fdbgpzumg6mvwroby8ek1nhvcognipuhiqnm/c0ysqz/u8xtmbs0jrld5 fdskuhd5t7gkna62wg7diph3htikrtdc9hibp3p/bfhz+jetgd8ym72uzp0lchpu njjda5m0pgjbtotlq70toq28kw8hsko9p6ctqsvbojxu7s6xsbq/g35npgvz3kic jlepakdxakwnorloi3wd+amitp0dov2fiw9do5a2xdbly1qltkrkxo+vm3lhcfab jflzjrp11yp+wcz3nijii9lbdnylo+6u2uoszwidaqabo4ic8dccauwwdgydvr0p aqh/baqdagwgmckga1udjqqimcagccsgaqufbwmcbggrbgefbqcdbaykkwybbagc nwodbdafbgnvhreegdawgrrqyxnvbi5ib3vybmvadmvklmnvbtadbgnvhq4efgqu sqcniz1456n8i0fi65omwb8+mxewhwydvr0jbbgwfoaumoum8wjiyz+n+ztdeocu i9xvxvgwgdmga1udhwsbyzcbydcbxacbwqcbv4abvgxkyxa6ly8vq049y2puzgvt by1dqsgxksxdtj1xsu4tm0ngndfoqlbuodusq049q0rqlenopvb1ymxpyyuymetl esuymfnlcnzpy2vzlenopvnlcnzpy2vzlenopunvbmzpz3vyyxrpb24srem9y2pu -----begin certificate-----
is there built in method in ruby, or there easy way this?
best regards
you can use ruby's base64
module re-encode string. module take correct padding account:
require "base64" str = "miiepaibaakcaqeayue3zaacnx50xrvh6csl05yjyxzrpmkfqlkfn4qfrbbkgogfy7nlf..." b64 = base64.encode64(base64.decode64(str)) pem = "-----begin certificate-----\n" << b64 << "-----end certificate-----\n" puts pem # -----begin certificate----- # miiepaibaakcaqeayue3zaacnx50xrvh6csl05yjyxzrpmkfqlkfn4qfrbbk # gogfy7nlfniccchg1kux8+bi5txoovf28qa7drizrz6hnyrxvmjkklhkczmg # hapefss3swk2knw6bzvqmo20fidib/fudzrsn0e9uixlowfcfodffs3h4bhk # ... # u2jscwcjat4dh8xhfdkgtyg+acrb75+pvgw7jpg3311n8suuf2eq3rwocdvz # uhd+tlunmqrw7ifpkhtl1po6ka/+g6xwh00zkxl5o6abmq/fzw6/yk5yx5pr # xuwhlycn6zvgjnenwmzkhvtawthhfw== # -----end certificate-----
Comments
Post a Comment