vb.net - How do I reload the formatted text into RTB? -


i have rtb in vb.net, , put event handler save formatted text file after encrypting it. however, can't figure out how reload formatting - when open it, shows symbols of formatting instead of formatted text. here's code:

dim filename string = textbox1.text file.delete(filename) dim encryptelement new tripledescryptoserviceprovider             encryptelement.key = {ascw("b"c), ascw("a"c), ascw("1"c), ascw("r"c), ascw("3"c), ascw("9"c), ascw("g"c), ascw("v"c), ascw("5"c), ascw("s"c), ascw("p"c), ascw("0"c), ascw("l"c), ascw("z"c), ascw("4"c), ascw("m"c)} '128 bit key             encryptelement.iv = {ascw("n"c), ascw("b"c), ascw("5"c), ascw("3"c), ascw("g"c), ascw("l"c), ascw("2"c), ascw("q"c)} ' 64 bit initialization vector  dim fstream filestream = file.open(filename, filemode.openorcreate) dim cstream new cryptostream(fstream, new tripledescryptoserviceprovider().createencryptor(encryptelement.key, encryptelement.iv), cryptostreammode.write)  dim swriter new streamwriter(cstream)  swriter.writeline(richtextbox1.rtf)  swriter.close() cstream.close() fstream.close() 

the above code saving, , below code opening.

dim filename string = textbox1.text dim decryptelement new tripledescryptoserviceprovider             decryptelement.key = {ascw("b"c), ascw("a"c), ascw("1"c), ascw("r"c), ascw("3"c), ascw("9"c), ascw("g"c), ascw("v"c), ascw("5"c), ascw("s"c), ascw("p"c), ascw("0"c), ascw("l"c), ascw("z"c), ascw("4"c), ascw("m"c)}             decryptelement.iv = {ascw("n"c), ascw("b"c), ascw("5"c), ascw("3"c), ascw("g"c), ascw("l"c), ascw("2"c), ascw("q"c)}   dim fstream filestream = file.open(filename, filemode.openorcreate)   dim cstream new cryptostream(fstream, new tripledescryptoserviceprovider().createdecryptor(decryptelement.key, decryptelement.iv), cryptostreammode.read)   dim sreader new streamreader(cstream)   dim decrypteddata string = ""   decrypteddata = sreader.readtoend   richtextbox1.appendtext(decrypteddata)  richtextbox1.enabled = true  button1.text = "ok"   sreader.close()  cstream.close()  fstream.close() 

where problem?

you need richtextbox1.savefile(somestream, richtextboxstreamtype) think streamwriter stuffing up.

oh , seeing gave world keys encryption might want come new one...

added after comment not proven though.

replace these 2 lines in save routine

dim swriter new streamwriter(cstream) swriter.writeline(richtextbox1.rtf) 

with

richtextbox1.savefile(cstream,richtextboxstreamtype.richtext); 

and rid of swriter.close()

i think.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -