473,569 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

saveing a txt file with a unique name?

9 New Member
How can i save a .txt file where the name of the file would be the result of the selection made from a Dom tree view's parent node tag in visual basic?
So for example i have an editable tree view form i add an entry to the tree view when i save it another process is started "part of which is an encryption scheme" the important part i need help with is saving the sharedkey as the value of the elements parent tag applied to a new addition to the tree and retrieving the key from a selected elements tag value. so for example i make a new account in my vb the new account code looks like this
Expand|Select|Wrap|Line Numbers
  1.  Private Sub saveNewAccount()       
  2.  
  3.         Dim objAccount As MSXML2.IXMLDOMElement
  4.         Dim objNewChild As MSXML2.IXMLDOMElement
  5.  
  6.         On Error GoTo ErrorHandler
  7.         If txtUsername.Text = "" Then
  8.         ElseIf txtPassword.Text = "" Then
  9.         ElseIf txtServer.Text = "" Then
  10.             Err.Number = 424
  11.             GoTo ErrorHandler
  12.             Exit Sub
  13.         Else
  14.  
  15.         End If
  16.  
  17.         objAccount = m_objDOMAccounts.createElement("Account")
  18.         objAccount.setAttribute("AccountID", txtUsername.Text)
  19.         m_objDOMAccounts.documentElement.appendChild(objAccount)
  20.  
  21.         objNewChild = m_objDOMAccounts.createElement("Username")
  22.         objNewChild.text = txtUsername.Text
  23.         objAccount.appendChild(objNewChild)
  24.  
  25.  
  26.         objNewChild = m_objDOMEQ2Accounts.createElement("EncryptedData")
  27.         objNewChild.text = txtPassword.Text
  28.         objAccount.appendChild(objNewChild)
  29.  
  30.  
  31.         objNewChild = m_objDOMEQ2Accounts.createElement("Server")
  32.         objNewChild.text = txtServer.Text
  33.         objAccount.appendChild(objNewChild)
  34.  
  35.         objNewChild = m_objDOMEQ2Accounts.createElement("Character")
  36.         objNewChild.text = txtCharacter.Text
  37.         objAccount.appendChild(objNewChild)
  38.  
  39.         populateTreeWithChildren(objAccount)
  40.         MsgBox("The Account was created!")
  41.  
  42.         'Error handling
  43. ErrorHandler:
  44.         If Err.Number = 424 Then
  45.             MsgBox("An Account Username, Password and Server are required to create a new account!")
  46.             If Err.Number = 1 Then
  47.                 MsgBox("That Account all ready exists! Please choose a different Account Username!")
  48.                 If Err.Number = 2 Then
  49.                     MsgBox("A different error!")
  50.                     If Err.Number = 3 Then
  51.                         MsgBox("Another error!")
  52.                     Else : MsgBox("Account was created but with errors! You should probably reset your data!")
  53.                     End If
  54.                 End If
  55.             End If
  56.         End If
  57.  
  58.         m_objDOMAccounts.save(m_strXmlPath)
  59.         Encrypt()
  60.         tvwAccounts.Refresh()
  61.         webTarget.Refresh()
  62.         'clear the object data from memory
  63.         objAccount = Nothing
  64.         objNewChild = Nothing
  65.  
  66.     End Sub
  67.  
The resulting out put xml is added to an existing xml doc looks like below.
the xml looks like this before encryption see the previous account is all ready encrypted after code finishes the second will be encrypted with its own unique key.

Expand|Select|Wrap|Line Numbers
  1. <Accounts>
  2.   <Account AccountID="MYNAME">
  3.     <Username>MYNAME</Username>
  4.     <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#">
  5.       <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
  6.       <CipherData>
  7.         <CipherValue>His98SF14aBCaV6we/frjsj3Mkx6R7KkRx4PLFIEzJh24NP8XIMllJqUaVSmORIUFUD482VAx/k=</CipherValue>
  8.       </CipherData>
  9.     </EncryptedData>
  10.     <Server>server</Server>
  11.     <Character>username</Character>
  12.   </Account>
  13. <Account AccountID="MYNAME2">
  14.     <Username>MYNAME2</Username>
  15.     <EncryptedData>passwordnotyetencrypted</EncryptedData>
  16.     <Server>server</Server>
  17.     <Character>username</Character>
  18.   </Account>
  19. </Accounts>
  20.  
the encryption and decryption schemes work fine the problem is each time a new account is added, edited or deleted a new sharedkey is written for the selected account. yet each encrypted data element needs its own individual sharedkey the result is data that cant be decrypted because the key was overwritten by the new or edited element! The key is created and read as in the codes below...

Expand|Select|Wrap|Line Numbers
  1. Dim sharedkey As New TripleDESCryptoServiceProvider()
  2.  
  3.  
  4.         Dim writer2 As IO.StreamWriter = New IO.StreamWriter("SharedTDESKey.txt")
  5.         Dim str As String = Convert.ToBase64String(sharedkey.Key)
  6.         writer2.WriteLine(str)
  7.         writer2.Close()
  8.  
Expand|Select|Wrap|Line Numbers
  1. Dim sharedkey As New TripleDESCryptoServiceProvider()
  2.  
  3.         Dim reader As IO.StreamReader = New IO.StreamReader(Application.StartupPath & "\sharedTDESkey.txt")
  4.         Dim data() As Byte = Convert.FromBase64String(reader.ReadToEnd)
  5.         'Assign the retrieved shared key value to the TripleDESCryptoServiceProvider object
  6.         sharedkey.Key = data
  7.  
What i need is the sharedTDESkey.t xt to be saved and read as something like
sharedTDESkey_M YNAME2.txt
or similar... something to make it unique to the account it is used for yet identifiable to the vb Dom tree view so it can later be called on to decrypt the data when need!
Its probably fairly simple by some standards but this is my first real project and ive overcome many of the more complicated obstacles yet get stuck on the simple ones... So any help is appreciated from an example to an explanation or just a suggestion! Peace All!
Aug 1 '07 #1
3 1706
deaddog4201
9 New Member
I tried various methods and no matter what the SharedTDESKey keeps that name and overwrites! I thought that this would have worked but no luck...

Expand|Select|Wrap|Line Numbers
  1. EncryptionKeyName = lblElement.Text
  2.  
  3. Dim FileName As String = EncryptionKeyName  &  "_"  &  "SharedTDESKey"
  4.         Dim sharedkey As New TripleDESCryptoServiceProvider()
  5.         Dim str As String = Convert.ToBase64String(sharedkey.Key)
  6.         Dim StuffToWrite As String = (str)
  7.         Dim strPath As String = strSaveToPath & FileName & ".txt"
  8.         Dim SW As StreamWriter
  9.         Dim FS2 As FileStream
  10.         FS2 = New FileStream(strPath, FileMode.Create)
  11.         SW = New StreamWriter(FS2)
  12.         SW.Write(StuffToWrite)
  13.         SW.Close()
  14.         FS2.Close()
  15.  
lblelement.text contains the info i want included in the file name
I was hoping to get Myaccount_Share dTDESKey.txt
Aug 2 '07 #2
deaddog4201
9 New Member
im begining to think theres not anyone here that knows anything at all of all the posts ive made here only 1 was answered and all i got was a link to the ms website you guys are genious....
Aug 4 '07 #3
Killer42
8,435 Recognized Expert Expert
im begining to think theres not anyone here that knows anything at all of all the posts ive made here only 1 was answered and all i got was a link to the ms website you guys are genious....
Sorry to hear you're not getting much response here, deaddog. We generally try to answer all questions. Unfortunately we seem to be a bit short on VB experts at the moment.

Since we are just volunteering our own time when we can spare it, it can be quite difficult to keep up.

You're quite welcome to join in and help improve the response.


P.S. I haven't tried to answer this one, as I don't know any XML.
Aug 4 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1638
by: sachin | last post by:
hi, I have link on my html page. when user click it it should call my.php in my.php i am getting result from database and want to show result in *.xls file. Can i call my.php/my.xls from my link . Currently i am getting error prematuture end of script. please help sachin
1
2906
by: DJTB | last post by:
zodb-dev@zope.org] Hi, I'm having problems storing large amounts of objects in a ZODB. After committing changes to the database, elements are not cleared from memory. Since the number of objects I'd like to store in the ZODB is too large to fit in RAM, my program gets killed with signal 11 or signal 9... Below a minimal working (or...
39
17917
by: Dave Theese | last post by:
Hello all, We're presented with the problem of needing to generate a unique file name. I've had some thoughts, but also wanted to solicit suggestions from the group. Any suggestions for schemes, using only *standard* C++, to do this? Thanks, Dave
0
3921
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header,...
3
1464
by: Manuel | last post by:
I've playing around with multi-threading applications lately. The main problem I have is that when I create a file/table/whatever I need a unique name. The only way I could come up with, is asking for a temporary file (System.IO.Path.GetTempFileName) and that file name would be the unique character string I was looking for. The same goes...
3
2751
by: ciaran.mchale | last post by:
Hi folks, I downloaded the binary version of Xerces C++ 2.7.0 for Windows and am using it to help me get up to speed with XML and XML Schema. So please excuse me if this is a "novice" question. In the samples/data directory, I ran the following command for all the files: DOMPrint -n -s -f -v=always <filename>
11
10273
by: Tarren | last post by:
Hi: I need to get the unique GUID for a file, so I am using API calls through System.InteropServices I am using BY_HANDLE_FILE_INFORMATION and
1
1830
by: fatjoez | last post by:
Hey there. I've been trying to modify my file upload script so that it handles 10 files instead of one. i was thinking the most straightforward way would be to add a FOR LOOP? placed strategically somewhere like just before the my variables get declared??? the POST input name is "fileup" so maybe i could call them fileup1, fileup2 etc. ...
1
1445
by: genesaika | last post by:
I am working on a rather basic text based adventure useing dev-C++ and running in DOS i am useing windows vista and XP. i made a menu type of area on the screen and if u change locations it labels where u are but if the locations name is too long it moves my borders for the menu... im looking to make the fonts change if the size of the info is too...
0
7695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.