c# - Selecting Multi-line strings through Entity Framework -
i using entity framework 4 in c# (yes know should upgrade thats besides point).
i have 70,000 private rsa keys stored in database format this: note - demo key
-----begin rsa private key----- miicxqidemodemodemodemodemoebgslt0n21onxrjbuwxfki7cn6clxpas+neuk bzaeijudjlqcga37ezv40uqnmgkplzo3ypee9qvkrvc4q3oi3s+ukfet7ejyvcwr wlnedoqvzydz8cwllce2yhoncmlyj3v3yst0n10oryakyaddbcd5pmbbuwieb7co +qkbgctldemodemodemodemodemonnvbwyfvlhfjpds1+5dtzbkog6zap+a/vkf1w 3psfl7vfbggqievai+4htulvzu0w0wqpqukw+rgzvt8fg1uwbrzukscjbscure/j 1i6iizz0sudjuynn+eorc12p1nrslf2buw3nfiognt849r9jakea1v+5agmjlzpp xz/etst7tb1wmeovnxu+s/h2kcw6+wcvlueryib2/e/lktbygxu5/ohimdgbqbb+ 28bu7lymuwjbam12343234235aeidmvgjchspoaqwnclv/fsex/6e8dxmhdhtena stt+v4k1rlkslm2aliz8kz2u8k45sepsvwecqqcmececqvtfuivc+8ekvlm536ot xrliedokrak8yrqqfezzaloxkotkixhbjuvt39spk+xzu30fwrdle858ebphakb+ lexh7ejtrxn3dhr1mdhjwolzm59dzgwfmueznnh+ommzsay21iouiaxjnkfxeclo frvuv5euqkvguji1/25jakaxzy7yjsjxanbgb9txakohhni2ywi/r9yewhzlorno oj49w6l9uawanxxmcrnzrizodemodemodemodemodemo -----end rsa private key-----
note: reason end rsa line doesnt format on stack overflow.
however, when try select key through entity framework, following: -----begin rsa private key-----
i believed might sql server (2008 in case) terminating string @ new line character ('\n') wrote stored proc try , replace server side, before being returned calling application.
ended this
declare @str nvarchar(max) declare @strreplaced nvarchar(max) set @str = (select privatekey privatekeys id = @id) set @strreplaced = (select (replace(@str, char(10), '<<newline>>'))) select @strreplaced
when run on sql server (the stored proc) - gives me private key appropriate <> replacements when execute stored proc via following c# code, still terminating result on first line of key.
var str = o.executestorequery<string>("execute dbo.getprivatekey " + id.tostring()); console.writeline(str.tolist()[0]);
can suggest solution allow c# code access whole rsa key?
when executing stored proc in sql server management studio: -----begin rsa private key-----<<newline>>miicxwibaakbgqducfrux55g9yqeznvzspx0yegudnrp0ip7jsmab0nvqagl/azo<<newline>>qbp5sne10mayjndsxbs0ahysorahapgkpgwtkoe5gfukxab1ejgidemodemodemodemo<<newline>>0pu0kma2/8znv23jfudro3sk8ft++at8crcs45ygnjvnsdgsu0mdemodemodemodemo<<newline>>awkbgaxv6pqrnvfueg5pt+0ijwtmehlqpbpeh5k2es1arykyl/t40fe5saximxwb<<newline>>f8suolxdpdodkxqbqzfos94hjtk6mrdzubn9mwl7f4d+b6/n4s+ydemodemodemodemo<<newline>>ker7drtf/n/kdrh/pty6pyhcfglvlmtg6cfyipncyyzviltdakea+rir/e+elyve<<newline>>bc+kpq9nlsxafz21r00pucujhrvbncvznkw2hv8d9ie4b+wmapcgh/7ghaiuc84o<<newline>>jpla8ejgpqjbapmlzgrwcvniuw7gl2ebiq33gdzvefzqc4kr5j2sflaa4lx/wkmj<<newline>>ymhjdjqlmo5nkd7qdmg0dwbusojccux/rpkcqqdxde/xx9kixd9nq2wv0dhq4lfu<<newline>>j/oxlxz2yd+tnr7lffn/qghu8vuc0g4erpr2kg5x6fbya3nq5midgl8j76pdakea<<newline>>pud2zrtmxbul8bdp4+gqll18jcrt0sv7fervamt+0gl/m2qamrevgd22ipkbbauv<<newline>>p4f1jtj6afqvq9n8rewtuwjbal4ilmt/gwg71pbqhplzlkdlmdgodf1ou6mylonv<<newline>>z24ja/emdx3jx1/wg7xyzqmejcvgk/8o/nwtp5dxqefblnw=<<newline>>-----end rsa private key-----<<newline>>
when executing stored proc via c# code: `string sconnectionstring = "insertconnectionstringhere"; using (var conn = new system.data.sqlclient.sqlconnection(sconnectionstring)) using (var command = new system.data.sqlclient.sqlcommand("getprivatekey", conn) { commandtype = commandtype.storedprocedure
}) { conn.open(); command.parameters.add(new system.data.sqlclient.sqlparameter("@domainid", vtransaction.domain.id)); var vreader = command.executereader(); vreader.read(); var vresult = vreader.getvalue(0); console.writeline(vresult); conn.close(); }`
it gives me -----begin rsa private key----- whatever cause is, affecting sql @ low level. impacts both direct raw sql , entity framework rests on top of it.
edit -- on closer inspection, using sql server express- have limitations might affect strings returned?
edit---- modified stored proc convert text field binary data , send caller. via code select convert(varbinary(max), @str )
it works on sql server, when called remotely via c# code, gets 62 bytes of data, when converted string - once again, bytes construct '-----begin rsa private key-----'
i @ loss....
use regex
using system; using system.collections.generic; using system.linq; using system.text; using system.text.regularexpressions; namespace consoleapplication2 { class program { static void main(string[] args) { string key = "-----begin rsa private key-----\n" + "miicxqidemodemodemodemodemoebgslt0n21onxrjbuwxfki7cn6clxpas+neuk\n" + "bzaeijudjlqcga37ezv40uqnmgkplzo3ypee9qvkrvc4q3oi3s+ukfet7ejyvcwr\n" + "wlnedoqvzydz8cwllce2yhoncmlyj3v3yst0n10oryakyaddbcd5pmbbuwieb7co\n" + "+qkbgctldemodemodemodemodemonnvbwyfvlhfjpds1+5dtzbkog6zap+a/vkf1w\n" + "3psfl7vfbggqievai+4htulvzu0w0wqpqukw+rgzvt8fg1uwbrzukscjbscure/j\n" + "1i6iizz0sudjuynn+eorc12p1nrslf2buw3nfiognt849r9jakea1v+5agmjlzpp\n" + "xz/etst7tb1wmeovnxu+s/h2kcw6+wcvlueryib2/e/lktbygxu5/ohimdgbqbb+\n" + "28bu7lymuwjbam12343234235aeidmvgjchspoaqwnclv/fsex/6e8dxmhdhtena\n" + "stt+v4k1rlkslm2aliz8kz2u8k45sepsvwecqqcmececqvtfuivc+8ekvlm536ot\n" + "xrliedokrak8yrqqfezzaloxkotkixhbjuvt39spk+xzu30fwrdle858ebphakb+\n" + "lexh7ejtrxn3dhr1mdhjwolzm59dzgwfmueznnh+ommzsay21iouiaxjnkfxeclo\n" + "frvuv5euqkvguji1/25jakaxzy7yjsjxanbgb9txakohhni2ywi/r9yewhzlorno\n" + "oj49w6l9uawanxxmcrnzrizodemodemodemodemodemo\n" + "-----end rsa private key-----\n"; regex expr = new regex("-.*$", regexoptions.multiline); key = expr.replace(key, "").trim(); } } }
Comments
Post a Comment