2017-06-02 94 views
-1

我已經開始一個新的應用程序來加密字符串,並將它們保存在我的設置代碼其工作正常,但它保存它保存多次相同。 我該如何將所有內容從列表框中保存到我的設置中,然後重複。 這是我的代碼保存my.settings文本多次保存vb.net

Imports System.Text 
Imports System.Security.Cryptography 
Imports System 
Imports System.Collections 
Imports System.Collections.Specialized 

Public Class Form1 


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
    'My.Settings.md5_hashes.Clear() 
End Sub 

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
    Dim md5 As MD5 = System.Security.Cryptography.MD5.Create() 
    Dim inputBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(TextBox1.Text) 
    Dim hash As Byte() = md5.ComputeHash(inputBytes) 
    Dim sb As New StringBuilder() 
    For i As Integer = 0 To hash.Length - 1 
     sb.Append(hash(i).ToString("x2")) 
    Next 
    TextBox2.Text = sb.ToString 
    ListBox1.Items.Add(TextBox1.Text + "<--->" + TextBox2.Text) 

    My.Settings.md5_hashes.Add(TextBox1.Text + "<--->" + TextBox2.Text) 

    My.Settings.Save() 





End Sub 

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click 

    For Each item In My.Settings.md5_hashes 
     ListBox1.Items.Add(item) 
    Next 
    Timer1.Start() 
End Sub 

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick 
    For Each item In My.Settings.md5_hashes 
     ListBox1.Items.Add(item) 
    Next 
End Sub 

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click 
    TextBox1.Text = "" 
    TextBox2.Text = "" 
End Sub 
End Class 
+0

散列與加密不同 - 它們不能被撤消。不知道你在問什麼 – Plutonix

回答

0

好吧,我只是解決了我自己的,因爲聞一開始計時了那裏的代碼來獲取所有的從我的設置列表框中的內容的問題。 我剛剛刪除並解決。