473,224 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

saveing a txt file with a unique name?

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 1689
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
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 Expert 8TB
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
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
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
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
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
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
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
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
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
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
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.