Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 4th, 2013  |  syntax: None  |  size: 3.85 KB  |  views: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Dim DES As New System.Security.Cryptography.TripleDESCryptoServiceProvider
  2.     Dim Hash As New System.Security.Cryptography.MD5CryptoServiceProvider
  3.     Try
  4.         DES.Key = Hash.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(My.Settings.Key))
  5.         DES.Mode = System.Security.Cryptography.CipherMode.ECB
  6.         Dim DESDecrypter As System.Security.Cryptography.ICryptoTransform = DES.CreateDecryptor
  7.         Dim Buffer As Byte() = Convert.FromBase64String(TextBoxCard.Text)
  8.         TextBoxCard.Text = System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
  9.     Catch ex As Exception
  10.         MessageBox.Show("The following error(s) have occurred: " & ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
  11.     End Try
  12.        
  13. Private Sub loadRecords()
  14.     'FOR MySQL DATABASE USE
  15.     Dim dbConn As New MySqlConnection
  16.     Dim dbTable As New DataTable
  17.     Dim dbQuery As String = ""
  18.     Dim dbCmd As New MySqlCommand
  19.     Dim dbAdapter As New MySqlDataAdapter
  20.     dbTable.Clear()
  21.  
  22.     Try
  23.  
  24.         If dbConn.State = ConnectionState.Closed Then
  25.             dbConn.ConnectionString = String.Format("Server={0};Port={1};Uid={2};Password={3};Database=accounting", FormLogin.ComboBoxServerIP.SelectedItem, My.Settings.DB_Port, My.Settings.DB_UserID, My.Settings.DB_Password)
  26.             dbConn.Open()
  27.         End If
  28.  
  29.         dbQuery = "SELECT *" & _
  30.                    "FROM cc_master INNER JOIN customer ON customer.accountNumber = cc_master.customer_accountNumber " & _
  31.                    "ORDER BY nameCOMPANY ASC"
  32.         With dbCmd
  33.             .CommandText = dbQuery
  34.             .Connection = dbConn
  35.         End With
  36.         With dbAdapter
  37.             .SelectCommand = dbCmd
  38.             .Fill(dbTable)
  39.         End With
  40.         ListViewRecords.Items.Clear()
  41.         For i = 0 To dbTable.Rows.Count - 1
  42.             With ListViewRecords
  43.                 .Items.Add(dbTable.Rows(i)("ccID"))
  44.                 With .Items(.Items.Count - 1).SubItems
  45.                     .Add(dbTable.Rows(i)("nameCOMPANY"))
  46.                     .Add(dbTable.Rows(i)("ccNumber"))
  47.                     .Add(dbTable.Rows(i)("ccExpireMonth"))
  48.                     .Add(dbTable.Rows(i)("ccExpireYear"))
  49.                     .Add(dbTable.Rows(i)("ccType"))
  50.                     .Add(dbTable.Rows(i)("ccAuthorizedUseStart"))
  51.                     .Add(dbTable.Rows(i)("ccAuthorizedUseEnd"))
  52.                     .Add(dbTable.Rows(i)("ccLocation"))
  53.                     .Add(dbTable.Rows(i)("cardholderSalutation"))
  54.                     .Add(dbTable.Rows(i)("cardholderLastname"))
  55.                     .Add(dbTable.Rows(i)("cardholderFirstname"))
  56.                     .Add(dbTable.Rows(i)("ccZipcode"))
  57.                 End With
  58.             End With
  59.         Next
  60.     Catch ex As MySqlException
  61.         MessageBox.Show("A DATABASE ERROR HAS OCCURED" & vbCrLf & vbCrLf & ex.Message & vbCrLf & _
  62.                     vbCrLf + "Please report this to the IT/Systems Helpdesk at Ext 131.")
  63.     End Try
  64.     dbConn.Close()
  65.  
  66. End Sub
  67.        
  68. Function Decrypt(ByVal ToDecrypt) as String
  69. Dim DES As New System.Security.Cryptography.TripleDESCryptoServiceProvider
  70.         Dim Hash As New System.Security.Cryptography.MD5CryptoServiceProvider
  71.         Try
  72.             DES.Key = Hash.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(My.Settings.Key))
  73.             DES.Mode = System.Security.Cryptography.CipherMode.ECB
  74.             Dim DESDecrypter As System.Security.Cryptography.ICryptoTransform = DES.CreateDecryptor
  75.             Dim Buffer As Byte() = Convert.FromBase64String(ToDecrypt)
  76.             return  System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
  77.         Catch ex As Exception
  78.             return "Whatever failed message you want"
  79.         End Try
  80. End Function
  81.        
  82. for i as Integer = 0 to dbTable.Rows.Count - 1
  83. dbTable.Rows(i)("ccNumber")) = Decrypt(dbTable.Rows(i)("ccNumber"))
clone this paste RAW Paste Data