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
- Private Sub saveNewAccount()
- Dim objAccount As MSXML2.IXMLDOMElement
- Dim objNewChild As MSXML2.IXMLDOMElement
- On Error GoTo ErrorHandler
- If txtUsername.Text = "" Then
- ElseIf txtPassword.Text = "" Then
- ElseIf txtServer.Text = "" Then
- Err.Number = 424
- GoTo ErrorHandler
- Exit Sub
- Else
- End If
- objAccount = m_objDOMAccounts.createElement("Account")
- objAccount.setAttribute("AccountID", txtUsername.Text)
- m_objDOMAccounts.documentElement.appendChild(objAccount)
- objNewChild = m_objDOMAccounts.createElement("Username")
- objNewChild.text = txtUsername.Text
- objAccount.appendChild(objNewChild)
- objNewChild = m_objDOMEQ2Accounts.createElement("EncryptedData")
- objNewChild.text = txtPassword.Text
- objAccount.appendChild(objNewChild)
- objNewChild = m_objDOMEQ2Accounts.createElement("Server")
- objNewChild.text = txtServer.Text
- objAccount.appendChild(objNewChild)
- objNewChild = m_objDOMEQ2Accounts.createElement("Character")
- objNewChild.text = txtCharacter.Text
- objAccount.appendChild(objNewChild)
- populateTreeWithChildren(objAccount)
- MsgBox("The Account was created!")
- 'Error handling
- ErrorHandler:
- If Err.Number = 424 Then
- MsgBox("An Account Username, Password and Server are required to create a new account!")
- If Err.Number = 1 Then
- MsgBox("That Account all ready exists! Please choose a different Account Username!")
- If Err.Number = 2 Then
- MsgBox("A different error!")
- If Err.Number = 3 Then
- MsgBox("Another error!")
- Else : MsgBox("Account was created but with errors! You should probably reset your data!")
- End If
- End If
- End If
- End If
- m_objDOMAccounts.save(m_strXmlPath)
- Encrypt()
- tvwAccounts.Refresh()
- webTarget.Refresh()
- 'clear the object data from memory
- objAccount = Nothing
- objNewChild = Nothing
- End Sub
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
- <Accounts>
- <Account AccountID="MYNAME">
- <Username>MYNAME</Username>
- <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#">
- <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
- <CipherData>
- <CipherValue>His98SF14aBCaV6we/frjsj3Mkx6R7KkRx4PLFIEzJh24NP8XIMllJqUaVSmORIUFUD482VAx/k=</CipherValue>
- </CipherData>
- </EncryptedData>
- <Server>server</Server>
- <Character>username</Character>
- </Account>
- <Account AccountID="MYNAME2">
- <Username>MYNAME2</Username>
- <EncryptedData>passwordnotyetencrypted</EncryptedData>
- <Server>server</Server>
- <Character>username</Character>
- </Account>
- </Accounts>
Expand|Select|Wrap|Line Numbers
- Dim sharedkey As New TripleDESCryptoServiceProvider()
- Dim writer2 As IO.StreamWriter = New IO.StreamWriter("SharedTDESKey.txt")
- Dim str As String = Convert.ToBase64String(sharedkey.Key)
- writer2.WriteLine(str)
- writer2.Close()
Expand|Select|Wrap|Line Numbers
- Dim sharedkey As New TripleDESCryptoServiceProvider()
- Dim reader As IO.StreamReader = New IO.StreamReader(Application.StartupPath & "\sharedTDESkey.txt")
- Dim data() As Byte = Convert.FromBase64String(reader.ReadToEnd)
- 'Assign the retrieved shared key value to the TripleDESCryptoServiceProvider object
- sharedkey.Key = data
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!