473,511 Members | 16,260 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.txt to be saved and read as something like
sharedTDESkey_MYNAME2.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 1703
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_SharedTDESKey.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
1637
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...
1
2903
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...
39
17908
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...
0
3910
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....
3
1456
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...
3
2746
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....
11
10267
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
1823
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...
1
1438
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...
0
7242
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,...
0
7138
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...
0
7353
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,...
0
7418
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...
0
7508
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5063
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...
0
3222
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...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.