|
I have some - so do lots of people. Some even share it. Try searching CP or Google.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
mighty_mouse wrote: need a sample code for email attachment
I need a brain. If I only had a brain... Do you think, the wizard of Oz has a brain for me?
|
|
|
|
|
The wizard got an HTTP 404 error when trying to upload it to you.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
Error 404 - cranial cavity not found
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
Only because I'm feeling helpful today :-
Dim oMail As New System.Net.Mail.MailMessage("senders@emailaddress.com", "reciepients@emailaddress.com")
oMail.Priority = Net.Mail.MailPriority.Normal
oMail.Subject = "My Subject"
oMail.Attachments.Add(New System.Net.Mail.Attachment("C:\My Documents\MyFile.Doc"))
oMail.IsBodyHtml = False
oMail.Body = "Please the file attached."
Dim smtp As New System.Net.Mail.SmtpClient("smtp.mailserver.net")
smtp.Credentials = New System.Net.NetworkCredential("myUserName", "MyPassword")
smtp.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
smtp.Send(oMail)
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Hi Friends,
Actually I want to Do Image Encryption and Image decryption but I really dont have so much concept for that,I have seen the Article Given by sudhakar79 but in that Article I Dont Know where did he got the Encrypted Data or how he did the Encryption.I looking for a Image Encryption and Decryption Program that must include the capability of adding Some Text in that encrypted data and then I can Decrypt That Data......I need Some Basic Details.......Can Any body Help Me Please
|
|
|
|
|
An image is just like any other binary file. Search codeproject for file encryption articles. There are quite a few.
What you are actually talking about doing is steganography.
|
|
|
|
|
Yes Dear Exactly I am talking about steganography where I have to Hide my Text Data behind an Image..........So dear Can you plz Help Me in This Context.......
|
|
|
|
|
I have VB code which gave you way how to Encryption and decryption but I don't know how to upload it into forum
--------------------------------------
Imports System
Imports System.IO
Imports System.Security
Imports System.Security.Cryptography
Public Class frmMain
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TabControl1 As System.Windows.Forms.TabControl
Friend WithEvents TabPage1 As System.Windows.Forms.TabPage
Friend WithEvents TabPage2 As System.Windows.Forms.TabPage
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label6 As System.Windows.Forms.Label
Friend WithEvents Label7 As System.Windows.Forms.Label
Friend WithEvents Label8 As System.Windows.Forms.Label
Friend WithEvents txtDestinationEncrypt As System.Windows.Forms.TextBox
Friend WithEvents btnEncrypt As System.Windows.Forms.Button
Friend WithEvents txtConPassEncrypt As System.Windows.Forms.TextBox
Friend WithEvents txtPassEncrypt As System.Windows.Forms.TextBox
Friend WithEvents txtFileToEncrypt As System.Windows.Forms.TextBox
Friend WithEvents pbStatus As System.Windows.Forms.ProgressBar
Friend WithEvents txtDestinationDecrypt As System.Windows.Forms.TextBox
Friend WithEvents btnDecrypt As System.Windows.Forms.Button
Friend WithEvents txtConPassDecrypt As System.Windows.Forms.TextBox
Friend WithEvents txtPassDecrypt As System.Windows.Forms.TextBox
Friend WithEvents txtFileToDecrypt As System.Windows.Forms.TextBox
Friend WithEvents btnChangeEncrypt As System.Windows.Forms.Button
Friend WithEvents btnBrowseEncrypt As System.Windows.Forms.Button
Friend WithEvents btnChangeDecrypt As System.Windows.Forms.Button
Friend WithEvents btnBrowseDecrypt As System.Windows.Forms.Button
Friend WithEvents OpenFileDialog As System.Windows.Forms.OpenFileDialog
Friend WithEvents FolderBrowserDialog As System.Windows.Forms.FolderBrowserDialog
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Me.TabControl1 = New System.Windows.Forms.TabControl
Me.TabPage1 = New System.Windows.Forms.TabPage
Me.btnChangeEncrypt = New System.Windows.Forms.Button
Me.txtDestinationEncrypt = New System.Windows.Forms.TextBox
Me.Label4 = New System.Windows.Forms.Label
Me.btnEncrypt = New System.Windows.Forms.Button
Me.txtConPassEncrypt = New System.Windows.Forms.TextBox
Me.txtPassEncrypt = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.btnBrowseEncrypt = New System.Windows.Forms.Button
Me.txtFileToEncrypt = New System.Windows.Forms.TextBox
Me.TabPage2 = New System.Windows.Forms.TabPage
Me.btnChangeDecrypt = New System.Windows.Forms.Button
Me.txtDestinationDecrypt = New System.Windows.Forms.TextBox
Me.Label5 = New System.Windows.Forms.Label
Me.btnDecrypt = New System.Windows.Forms.Button
Me.txtConPassDecrypt = New System.Windows.Forms.TextBox
Me.txtPassDecrypt = New System.Windows.Forms.TextBox
Me.Label6 = New System.Windows.Forms.Label
Me.Label7 = New System.Windows.Forms.Label
Me.Label8 = New System.Windows.Forms.Label
Me.btnBrowseDecrypt = New System.Windows.Forms.Button
Me.txtFileToDecrypt = New System.Windows.Forms.TextBox
Me.pbStatus = New System.Windows.Forms.ProgressBar
Me.OpenFileDialog = New System.Windows.Forms.OpenFileDialog
Me.FolderBrowserDialog = New System.Windows.Forms.FolderBrowserDialog
Me.TabControl1.SuspendLayout()
Me.TabPage1.SuspendLayout()
Me.TabPage2.SuspendLayout()
Me.SuspendLayout()
'
'TabControl1
'
Me.TabControl1.Controls.Add(Me.TabPage1)
Me.TabControl1.Controls.Add(Me.TabPage2)
Me.TabControl1.Location = New System.Drawing.Point(0, 0)
Me.TabControl1.Name = "TabControl1"
Me.TabControl1.SelectedIndex = 0
Me.TabControl1.Size = New System.Drawing.Size(384, 144)
Me.TabControl1.TabIndex = 0
'
'TabPage1
'
Me.TabPage1.BackColor = System.Drawing.SystemColors.Control
Me.TabPage1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.TabPage1.Controls.Add(Me.btnChangeEncrypt)
Me.TabPage1.Controls.Add(Me.txtDestinationEncrypt)
Me.TabPage1.Controls.Add(Me.Label4)
Me.TabPage1.Controls.Add(Me.btnEncrypt)
Me.TabPage1.Controls.Add(Me.txtConPassEncrypt)
Me.TabPage1.Controls.Add(Me.txtPassEncrypt)
Me.TabPage1.Controls.Add(Me.Label1)
Me.TabPage1.Controls.Add(Me.Label3)
Me.TabPage1.Controls.Add(Me.Label2)
Me.TabPage1.Controls.Add(Me.btnBrowseEncrypt)
Me.TabPage1.Controls.Add(Me.txtFileToEncrypt)
Me.TabPage1.Location = New System.Drawing.Point(4, 22)
Me.TabPage1.Name = "TabPage1"
Me.TabPage1.Size = New System.Drawing.Size(376, 118)
Me.TabPage1.TabIndex = 0
Me.TabPage1.Text = "Encrypt File"
'
'btnChangeEncrypt
'
Me.btnChangeEncrypt.Enabled = False
Me.btnChangeEncrypt.Location = New System.Drawing.Point(296, 32)
Me.btnChangeEncrypt.Name = "btnChangeEncrypt"
Me.btnChangeEncrypt.Size = New System.Drawing.Size(72, 21)
Me.btnChangeEncrypt.TabIndex = 11
Me.btnChangeEncrypt.Text = "Change"
'
'txtDestinationEncrypt
'
Me.txtDestinationEncrypt.Location = New System.Drawing.Point(104, 32)
Me.txtDestinationEncrypt.Name = "txtDestinationEncrypt"
Me.txtDestinationEncrypt.ReadOnly = True
Me.txtDestinationEncrypt.Size = New System.Drawing.Size(184, 20)
Me.txtDestinationEncrypt.TabIndex = 10
Me.txtDestinationEncrypt.Text = ""
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(8, 32)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(88, 16)
Me.Label4.TabIndex = 9
Me.Label4.Text = "File destination:"
Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'btnEncrypt
'
Me.btnEncrypt.Enabled = False
Me.btnEncrypt.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnEncrypt.Location = New System.Drawing.Point(296, 72)
Me.btnEncrypt.Name = "btnEncrypt"
Me.btnEncrypt.Size = New System.Drawing.Size(72, 32)
Me.btnEncrypt.TabIndex = 8
Me.btnEncrypt.Text = "Encrypt"
'
'txtConPassEncrypt
'
Me.txtConPassEncrypt.Location = New System.Drawing.Point(104, 88)
Me.txtConPassEncrypt.Name = "txtConPassEncrypt"
Me.txtConPassEncrypt.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.txtConPassEncrypt.Size = New System.Drawing.Size(184, 20)
Me.txtConPassEncrypt.TabIndex = 7
Me.txtConPassEncrypt.Text = ""
'
'txtPassEncrypt
'
Me.txtPassEncrypt.Location = New System.Drawing.Point(104, 64)
Me.txtPassEncrypt.Name = "txtPassEncrypt"
Me.txtPassEncrypt.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.txtPassEncrypt.Size = New System.Drawing.Size(184, 20)
Me.txtPassEncrypt.TabIndex = 6
Me.txtPassEncrypt.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(16, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(80, 16)
Me.Label1.TabIndex = 5
Me.Label1.Text = "File to encrypt:"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(-8, 88)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(104, 16)
Me.Label3.TabIndex = 4
Me.Label3.Text = "Confirm password:"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(8, 64)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(88, 16)
Me.Label2.TabIndex = 3
Me.Label2.Text = "Type password:"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'btnBrowseEncrypt
'
Me.btnBrowseEncrypt.Location = New System.Drawing.Point(296, 8)
Me.btnBrowseEncrypt.Name = "btnBrowseEncrypt"
Me.btnBrowseEncrypt.Size = New System.Drawing.Size(72, 21)
Me.btnBrowseEncrypt.TabIndex = 2
Me.btnBrowseEncrypt.Text = "Browse"
'
'txtFileToEncrypt
'
Me.txtFileToEncrypt.Location = New System.Drawing.Point(104, 8)
Me.txtFileToEncrypt.Name = "txtFileToEncrypt"
Me.txtFileToEncrypt.ReadOnly = True
Me.txtFileToEncrypt.Size = New System.Drawing.Size(184, 20)
Me.txtFileToEncrypt.TabIndex = 1
Me.txtFileToEncrypt.Text = "Click Browse to load file."
'
'TabPage2
'
Me.TabPage2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.TabPage2.Controls.Add(Me.btnChangeDecrypt)
Me.TabPage2.Controls.Add(Me.txtDestinationDecrypt)
Me.TabPage2.Controls.Add(Me.Label5)
Me.TabPage2.Controls.Add(Me.btnDecrypt)
Me.TabPage2.Controls.Add(Me.txtConPassDecrypt)
Me.TabPage2.Controls.Add(Me.txtPassDecrypt)
Me.TabPage2.Controls.Add(Me.Label6)
Me.TabPage2.Controls.Add(Me.Label7)
Me.TabPage2.Controls.Add(Me.Label8)
Me.TabPage2.Controls.Add(Me.btnBrowseDecrypt)
Me.TabPage2.Controls.Add(Me.txtFileToDecrypt)
Me.TabPage2.Location = New System.Drawing.Point(4, 22)
Me.TabPage2.Name = "TabPage2"
Me.TabPage2.Size = New System.Drawing.Size(376, 118)
Me.TabPage2.TabIndex = 1
Me.TabPage2.Text = "Decrypt File"
'
'btnChangeDecrypt
'
Me.btnChangeDecrypt.Enabled = False
Me.btnChangeDecrypt.Location = New System.Drawing.Point(296, 32)
Me.btnChangeDecrypt.Name = "btnChangeDecrypt"
Me.btnChangeDecrypt.Size = New System.Drawing.Size(72, 21)
Me.btnChangeDecrypt.TabIndex = 22
Me.btnChangeDecrypt.Text = "Change"
'
'txtDestinationDecrypt
'
Me.txtDestinationDecrypt.Location = New System.Drawing.Point(104, 32)
Me.txtDestinationDecrypt.Name = "txtDestinationDecrypt"
Me.txtDestinationDecrypt.ReadOnly = True
Me.txtDestinationDecrypt.Size = New System.Drawing.Size(184, 20)
Me.txtDestinationDecrypt.TabIndex = 21
Me.txtDestinationDecrypt.Text = ""
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(8, 32)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(88, 16)
Me.Label5.TabIndex = 20
Me.Label5.Text = "File destination:"
Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'btnDecrypt
'
Me.btnDecrypt.Enabled = False
Me.btnDecrypt.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnDecrypt.Location = New System.Drawing.Point(296, 72)
Me.btnDecrypt.Name = "btnDecrypt"
Me.btnDecrypt.Size = New System.Drawing.Size(72, 32)
Me.btnDecrypt.TabIndex = 19
Me.btnDecrypt.Text = "Decrypt"
'
'txtConPassDecrypt
'
Me.txtConPassDecrypt.Location = New System.Drawing.Point(104, 88)
Me.txtConPassDecrypt.Name = "txtConPassDecrypt"
Me.txtConPassDecrypt.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.txtConPassDecrypt.Size = New System.Drawing.Size(184, 20)
Me.txtConPassDecrypt.TabIndex = 18
Me.txtConPassDecrypt.Text = ""
'
'txtPassDecrypt
'
Me.txtPassDecrypt.Location = New System.Drawing.Point(104, 64)
Me.txtPassDecrypt.Name = "txtPassDecrypt"
Me.txtPassDecrypt.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.txtPassDecrypt.Size = New System.Drawing.Size(184, 20)
Me.txtPassDecrypt.TabIndex = 17
Me.txtPassDecrypt.Text = ""
'
'Label6
'
Me.Label6.Location = New System.Drawing.Point(16, 8)
Me.Label6.Name = "Label6"
Me.Label6.Size = New System.Drawing.Size(80, 16)
Me.Label6.TabIndex = 16
Me.Label6.Text = "File to decrypt:"
Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Label7
'
Me.Label7.Location = New System.Drawing.Point(-8, 88)
Me.Label7.Name = "Label7"
Me.Label7.Size = New System.Drawing.Size(104, 16)
Me.Label7.TabIndex = 15
Me.Label7.Text = "Confirm password:"
Me.Label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Label8
'
Me.Label8.Location = New System.Drawing.Point(8, 64)
Me.Label8.Name = "Label8"
Me.Label8.Size = New System.Drawing.Size(88, 16)
Me.Label8.TabIndex = 14
Me.Label8.Text = "Type password:"
Me.Label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'btnBrowseDecrypt
'
Me.btnBrowseDecrypt.Location = New System.Drawing.Point(296, 8)
Me.btnBrowseDecrypt.Name = "btnBrowseDecrypt"
Me.btnBrowseDecrypt.Size = New System.Drawing.Size(72, 21)
Me.btnBrowseDecrypt.TabIndex = 13
Me.btnBrowseDecrypt.Text = "Browse"
'
'txtFileToDecrypt
'
Me.txtFileToDecrypt.Location = New System.Drawing.Point(104, 8)
Me.txtFileToDecrypt.Name = "txtFileToDecrypt"
Me.txtFileToDecrypt.ReadOnly = True
Me.txtFileToDecrypt.Size = New System.Drawing.Size(184, 20)
Me.txtFileToDecrypt.TabIndex = 12
Me.txtFileToDecrypt.Text = "Click Browse to load file."
'
'pbStatus
'
Me.pbStatus.Location = New System.Drawing.Point(0, 144)
Me.pbStatus.Name = "pbStatus"
Me.pbStatus.Size = New System.Drawing.Size(384, 16)
Me.pbStatus.TabIndex = 1
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(382, 156)
Me.Controls.Add(Me.pbStatus)
Me.Controls.Add(Me.TabControl1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
Me.Name = "frmMain"
Me.Text = "Encrypt / Decrypt File (Using Rijndael)"
Me.TabControl1.ResumeLayout(False)
Me.TabPage1.ResumeLayout(False)
Me.TabPage2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
#Region "1. Global Variables "
'*************************
'** Global Variables
'*************************
Dim strFileToEncrypt As String
Dim strFileToDecrypt As String
Dim strOutputEncrypt As String
Dim strOutputDecrypt As String
Dim fsInput As System.IO.FileStream
Dim fsOutput As System.IO.FileStream
#End Region
#Region "2. Create A Key "
'*************************
'** Create A Key
'*************************
Private Function CreateKey(ByVal strPassword As String) As Byte()
'Convert strPassword to an array and store in chrData.
Dim chrData() As Char = strPassword.ToCharArray
'Use intLength to get strPassword size.
Dim intLength As Integer = chrData.GetUpperBound(0)
'Declare bytDataToHash and make it the same size as chrData.
Dim bytDataToHash(intLength) As Byte
'Use For Next to convert and store chrData into bytDataToHash.
For i As Integer = 0 To chrData.GetUpperBound(0)
bytDataToHash(i) = CByte(Asc(chrData(i)))
Next
'Declare what hash to use.
Dim SHA512 As New System.Security.Cryptography.SHA512Managed
'Declare bytResult, Hash bytDataToHash and store it in bytResult.
Dim bytResult As Byte() = SHA512.ComputeHash(bytDataToHash)
'Declare bytKey(31). It will hold 256 bits.
Dim bytKey(31) As Byte
'Use For Next to put a specific size (256 bits) of
'bytResult into bytKey. The 0 To 31 will put the first 256 bits
'of 512 bits into bytKey.
For i As Integer = 0 To 31
bytKey(i) = bytResult(i)
Next
Return bytKey 'Return the key.
End Function
#End Region
#Region "3. Create An IV "
'*************************
'** Create An IV
'*************************
Private Function CreateIV(ByVal strPassword As String) As Byte()
'Convert strPassword to an array and store in chrData.
Dim chrData() As Char = strPassword.ToCharArray
'Use intLength to get strPassword size.
Dim intLength As Integer = chrData.GetUpperBound(0)
'Declare bytDataToHash and make it the same size as chrData.
Dim bytDataToHash(intLength) As Byte
'Use For Next to convert and store chrData into bytDataToHash.
For i As Integer = 0 To chrData.GetUpperBound(0)
bytDataToHash(i) = CByte(Asc(chrData(i)))
Next
'Declare what hash to use.
Dim SHA512 As New System.Security.Cryptography.SHA512Managed
'Declare bytResult, Hash bytDataToHash and store it in bytResult.
Dim bytResult As Byte() = SHA512.ComputeHash(bytDataToHash)
'Declare bytIV(15). It will hold 128 bits.
Dim bytIV(15) As Byte
'Use For Next to put a specific size (128 bits) of
'bytResult into bytIV. The 0 To 30 for bytKey used the first 256 bits.
'of the hashed password. The 32 To 47 will put the next 128 bits into bytIV.
For i As Integer = 32 To 47
bytIV(i - 32) = bytResult(i)
Next
Return bytIV 'return the IV
End Function
#End Region
#Region "4. Encrypt / Decrypt File "
'****************************
'** Encrypt/Decrypt File
'****************************
Private Enum CryptoAction
'Define the enumeration for CryptoAction.
ActionEncrypt = 1
ActionDecrypt = 2
End Enum
Private Sub EncryptOrDecryptFile(ByVal strInputFile As String, _
ByVal strOutputFile As String, _
ByVal bytKey() As Byte, _
ByVal bytIV() As Byte, _
ByVal Direction As CryptoAction)
Try 'In case of errors.
'Setup file streams to handle input and output.
fsInput = New System.IO.FileStream(strInputFile, FileMode.Open, _
FileAccess.Read)
fsOutput = New System.IO.FileStream(strOutputFile, FileMode.OpenOrCreate, _
FileAccess.Write)
fsOutput.SetLength(0) 'make sure fsOutput is empty
'Declare variables for encrypt/decrypt process.
Dim bytBuffer(4096) As Byte 'holds a block of bytes for processing
Dim lngBytesProcessed As Long = 0 'running count of bytes processed
Dim lngFileLength As Long = fsInput.Length 'the input file's length
Dim intBytesInCurrentBlock As Integer 'current bytes being processed
Dim csCryptoStream As CryptoStream
'Declare your CryptoServiceProvider.
Dim cspRijndael As New System.Security.Cryptography.RijndaelManaged
'Setup Progress Bar
pbStatus.Value = 0
pbStatus.Maximum = 100
'Determine if ecryption or decryption and setup CryptoStream.
Select Case Direction
Case CryptoAction.ActionEncrypt
csCryptoStream = New CryptoStream(fsOutput, _
cspRijndael.CreateEncryptor(bytKey, bytIV), _
CryptoStreamMode.Write)
Case CryptoAction.ActionDecrypt
csCryptoStream = New CryptoStream(fsOutput, _
cspRijndael.CreateDecryptor(bytKey, bytIV), _
CryptoStreamMode.Write)
End Select
'Use While to loop until all of the file is processed.
While lngBytesProcessed < lngFileLength
'Read file with the input filestream.
intBytesInCurrentBlock = fsInput.Read(bytBuffer, 0, 4096)
'Write output file with the cryptostream.
csCryptoStream.Write(bytBuffer, 0, intBytesInCurrentBlock)
'Update lngBytesProcessed
lngBytesProcessed = lngBytesProcessed + CLng(intBytesInCurrentBlock)
'Update Progress Bar
pbStatus.Value = CInt((lngBytesProcessed / lngFileLength) * 100)
End While
'Close FileStreams and CryptoStream.
csCryptoStream.Close()
fsInput.Close()
fsOutput.Close()
'If encrypting then delete the original unencrypted file.
If Direction = CryptoAction.ActionEncrypt Then
Dim fileOriginal As New FileInfo(strFileToEncrypt)
fileOriginal.Delete()
End If
'If decrypting then delete the encrypted file.
If Direction = CryptoAction.ActionDecrypt Then
Dim fileEncrypted As New FileInfo(strFileToDecrypt)
fileEncrypted.Delete()
End If
'Update the user when the file is done.
Dim Wrap As String = Chr(13) + Chr(10)
If Direction = CryptoAction.ActionEncrypt Then
MsgBox("Encryption Complete" + Wrap + Wrap + _
"Total bytes processed = " + _
lngBytesProcessed.ToString, _
MsgBoxStyle.Information, "Done")
'Update the progress bar and textboxes.
pbStatus.Value = 0
txtFileToEncrypt.Text = "Click Browse to load file."
txtPassEncrypt.Text = ""
txtConPassEncrypt.Text = ""
txtDestinationEncrypt.Text = ""
btnChangeEncrypt.Enabled = False
btnEncrypt.Enabled = False
Else
'Update the user when the file is done.
MsgBox("Decryption Complete" + Wrap + Wrap + _
"Total bytes processed = " + _
lngBytesProcessed.ToString, _
MsgBoxStyle.Information, "Done")
'Update the progress bar and textboxes.
pbStatus.Value = 0
txtFileToDecrypt.Text = "Click Browse to load file."
txtPassDecrypt.Text = ""
txtConPassDecrypt.Text = ""
txtDestinationDecrypt.Text = ""
btnChangeDecrypt.Enabled = False
btnDecrypt.Enabled = False
End If
'Catch file not found error.
Catch When Err.Number = 53 'if file not found
MsgBox("Please check to make sure the path and filename" + _
"are correct and if the file exists.", _
MsgBoxStyle.Exclamation, "Invalid Path or Filename")
'Catch all other errors. And delete partial files.
Catch
fsInput.Close()
fsOutput.Close()
If Direction = CryptoAction.ActionDecrypt Then
Dim fileDelete As New FileInfo(txtDestinationDecrypt.Text)
fileDelete.Delete()
pbStatus.Value = 0
txtPassDecrypt.Text = ""
txtConPassDecrypt.Text = ""
MsgBox("Please check to make sure that you entered the correct" + _
"password.", MsgBoxStyle.Exclamation, "Invalid Password")
Else
Dim fileDelete As New FileInfo(txtDestinationEncrypt.Text)
fileDelete.Delete()
pbStatus.Value = 0
txtPassEncrypt.Text = ""
txtConPassEncrypt.Text = ""
MsgBox("This file cannot be encrypted.", _
MsgBoxStyle.Exclamation, "Invalid File")
End If
End Try
End Sub
#End Region
#Region "5. Browse / Change Button "
'******************************
'** Browse/Change Buttons
'******************************
Private Sub btnBrowseEncrypt_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnBrowseEncrypt.Click
'Setup the open dialog.
OpenFileDialog.FileName = ""
OpenFileDialog.Title = "Choose a file to encrypt"
OpenFileDialog.InitialDirectory = "C:\"
OpenFileDialog.Filter = "All Files (*.*) | *.*"
'Find out if the user chose a file.
If OpenFileDialog.ShowDialog = DialogResult.OK Then
strFileToEncrypt = OpenFileDialog.FileName
txtFileToEncrypt.Text = strFileToEncrypt
Dim iPosition As Integer = 0
Dim i As Integer = 0
'Get the position of the last "\" in the OpenFileDialog.FileName path.
'-1 is when the character your searching for is not there.
'IndexOf searches from left to right.
While strFileToEncrypt.IndexOf("\"c, i) <> -1
iPosition = strFileToEncrypt.IndexOf("\"c, i)
i = iPosition + 1
End While
'Assign strOutputFile to the position after the last "\" in the path.
'This position is the beginning of the file name.
strOutputEncrypt = strFileToEncrypt.Substring(iPosition + 1)
'Assign S the entire path, ending at the last "\".
Dim S As String = strFileToEncrypt.Substring(0, iPosition + 1)
'Replace the "." in the file extension with "_".
strOutputEncrypt = strOutputEncrypt.Replace("."c, "_"c)
'The final file name. XXXXX.encrypt
txtDestinationEncrypt.Text = S + strOutputEncrypt + ".encrypt"
'Update buttons.
btnEncrypt.Enabled = True
btnChangeEncrypt.Enabled = True
End If
End Sub
Private Sub btnBrowseDecrypt_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnBrowseDecrypt.Click
'Setup the open dialog.
OpenFileDialog.FileName = ""
OpenFileDialog.Title = "Choose a file to decrypt"
OpenFileDialog.InitialDirectory = "C:\"
OpenFileDialog.Filter = "Encrypted Files (*.encrypt) | *.encrypt"
'Find out if the user chose a file.
If OpenFileDialog.ShowDialog = DialogResult.OK Then
strFileToDecrypt = OpenFileDialog.FileName
txtFileToDecrypt.Text = strFileToDecrypt
Dim iPosition As Integer = 0
Dim i As Integer = 0
'Get the position of the last "\" in the OpenFileDialog.FileName path.
'-1 is when the character your searching for is not there.
'IndexOf searches from left to right.
While strFileToDecrypt.IndexOf("\"c, i) <> -1
iPosition = strFileToDecrypt.IndexOf("\"c, i)
i = iPosition + 1
End While
'strOutputFile = the file path minus the last 8 characters (.encrypt)
strOutputDecrypt = strFileToDecrypt.Substring(0, strFileToDecrypt.Length - 8)
'Assign S the entire path, ending at the last "\".
Dim S As String = strFileToDecrypt.Substring(0, iPosition + 1)
'Assign strOutputFile to the position after the last "\" in the path.
strOutputDecrypt = strOutputDecrypt.Substring((iPosition + 1))
'Replace "_" with "."
txtDestinationDecrypt.Text = S + strOutputDecrypt.Replace("_"c, "."c)
'Update buttons
btnDecrypt.Enabled = True
btnChangeDecrypt.Enabled = True
End If
End Sub
Private Sub btnChangeEncrypt_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnChangeEncrypt.Click
'Setup up folder browser.
FolderBrowserDialog.Description = "Select a folder to place the encrypted file in."
'If the user selected a folder assign the path to txtDestinationEncrypt.
If FolderBrowserDialog.ShowDialog = DialogResult.OK Then
txtDestinationEncrypt.Text = FolderBrowserDialog.SelectedPath + _
"\" + strOutputEncrypt + ".encrypt"
End If
End Sub
Private Sub btnChangeDecrypt_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnChangeDecrypt.Click
'Setup up folder browser.
FolderBrowserDialog.Description = "Select a folder for to place the decrypted file in."
'If the user selected a folder assign the path to txtDestinationDecrypt.
If FolderBrowserDialog.ShowDialog = DialogResult.OK Then
txtDestinationDecrypt.Text = FolderBrowserDialog.SelectedPath + _
"\" + strOutputDecrypt.Replace("_"c, "."c)
End If
End Sub
#End Region
#Region "6. Encrypt / Decrypt Buttons "
'******************************
'** Encrypt/Decrypt Buttons
'******************************
Private Sub btnEncrypt_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnEncrypt.Click
'Make sure the password is correct.
If txtConPassEncrypt.Text = txtPassEncrypt.Text Then
'Declare variables for the key and iv.
'The key needs to hold 256 bits and the iv 128 bits.
Dim bytKey As Byte()
Dim bytIV As Byte()
'Send the password to the CreateKey function.
bytKey = CreateKey(txtPassEncrypt.Text)
'Send the password to the CreateIV function.
bytIV = CreateIV(txtPassEncrypt.Text)
'Start the encryption.
EncryptOrDecryptFile(strFileToEncrypt, txtDestinationEncrypt.Text, _
bytKey, bytIV, CryptoAction.ActionEncrypt)
Else
MsgBox("Please re-enter your password.", MsgBoxStyle.Exclamation)
txtPassEncrypt.Text = ""
txtConPassEncrypt.Text = ""
End If
End Sub
Private Sub btnDecrypt_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnDecrypt.Click
'Make sure the password is correct.
If txtConPassDecrypt.Text = txtPassDecrypt.Text Then
'Declare variables for the key and iv.
'The key needs to hold 256 bits and the iv 128 bits.
Dim bytKey As Byte()
Dim bytIV As Byte()
'Send the password to the CreateKey function.
bytKey = CreateKey(txtPassDecrypt.Text)
'Send the password to the CreateIV function.
bytIV = CreateIV(txtPassDecrypt.Text)
'Start the decryption.
EncryptOrDecryptFile(strFileToDecrypt, txtDestinationDecrypt.Text, _
bytKey, bytIV, CryptoAction.ActionDecrypt)
Else
MsgBox("Please re-enter your password.", MsgBoxStyle.Exclamation)
txtPassDecrypt.Text = ""
txtConPassDecrypt.Text = ""
End If
End Sub
#End Region
End Class
----------
----------
This will appear at the end of articles you submit to the Code Project
|
|
|
|
|
If you post code, you should only post the code that is relevant to the question, not the entire project. About 80% of the code you posted is auto-generated and/or UI related, so it could just have been left out.
For code longer than a few lines you should use a code block, so that it doesn't lose the formatting.
And go into your settings and change your signature, or at least remove the default "This will appear at the end of articles you submit to the Code Project" text.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi Dear,
Thanks Dear for your help but dear Actually I am Looking for steganography which means I have to hide my text data behind An image and then Retrieve That Data from the image......the Example you gave me Was difficult To understand for me...........Please can you help me more......
|
|
|
|
|
hi i have an apllication build ( with help !! much help from japarbz )
that opens links like :
http://www.google/userid=1
then http://www.google/userid=2
and so further ..
its an dynamic hyperlink with vazriable i
but now , its a difficult part ( i think)
first
a link has to open ( with the application)
so : http://www.google/userid=1
then , a button on that page has to be clicked
then the page goes like ; http://www.google/userid=1/completed ( example)
then yes , : http://www.google/userid=2 has to open
again , a button on that page has to be clicked ( the same button , same place , so maybe a can use an auto mouse clicker) ?
but i cant take the final url of example -> http://www.google/userid=1/completed cause it wont work so i have to use something like an auto mouseclicker
someone knows how to change the source that i dont have to use an extern auto mouse clicker ?
or someone another idea
here is the source of the appl that i have now ;
Option Explicit
Dim i As Integer
Dim j As Integer
Dim t As Integer
Dim SaveStr As String
Private Sub Command1_Click()
Dim msg As String
msg = InputBox("How many times want to repeat ?", "repeat", 0)
If IsNull(msg) = False And IsNumeric(msg) = True Then
t = CInt(msg)
Else
Timer1.Enabled = False
End If
Timer1.Enabled = True
SaveStr = Text1.Text
End Sub
Private Sub Form_Load()
i = 1
Timer1.Interval = 100
Timer1.Enabled = False
End Sub
Private Sub Form_Resize()
Text1.Width = Me.Width
WebBrowser1.Width = Me.Width
WebBrowser1.Height = Me.Height
Command1.Left = Me.Width - Command1.Width
End Sub
Private Sub Timer1_Timer()
If WebBrowser1.Busy = False Then
WebBrowser1.Navigate SaveStr + CStr(i)
Text1.Text = SaveStr + CStr(i)
i = i + 1
If i = t + 1 Then
Timer1.Enabled = False
Text1.Text = vbNullString
t = 0
i = 1
End If
End If
End Sub
|
|
|
|
|
how to use report viewer in win application? please help me
Thanks
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
Be more specific. Your question is way to vague.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Can anyone uses the following library tell me more on how to use them?? And please advise any books or website where there is description and example of the following library... Thanks a lot in advance..
|
|
|
|
|
Subjugate wrote: website where there is description and example of the following library...
Have you even considered doing a google search on it?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Yup i done that before already but the did not show anything relevant.. That's y i am a bit lost now and deadline is drawing near.
|
|
|
|
|
Hey,
I want to store a list of products in a database. I've tried XML, but the problem is: I can't store special characters. (Actually, there are ways, but I need something simplistic ) So: does anyone have ideas on saving a list of products in a database, which I can edit and read with ease? I am using Visual Studio 2005 with Visual Basic.
I want to store it like this:
<code>
[Groupname]
[Brandname]
[Productname]
[Price]3,99[/Price]
[ItemID]12345[/ItemID]
[Description]""[/Description]
[/Productname]
[/Brandname]
[/Groupname]
</code>
Remember: I need to save special characters (in the names aswell!)
Thanks in advance!
Motivation is the key to software development.
modified on Sunday, September 21, 2008 8:26 AM
|
|
|
|
|
Seems like a straightforward database design, where is your problem exactly?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Well, i'd like to know what's the best way of saving that list of products including special characters
Motivation is the key to software development.
|
|
|
|
|
Depending on the volume/number of users I would use either sql server or sql server express. In either case nvarchar is the datatype you require.
Hope this helps
Bob
Ashfield Consultants Ltd
|
|
|
|
|
SQL, MSAccess, Oracle
Personally i would either use Microsoft Access or create a new file format for my purposes.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
Hello everybody,
being rather new to VB.NET (VS 2008 Express) I have to admit that I study much more than producing results. So first of all: Thank you everybody in here for an invaluable source of inspiration, which is highly appreciated!
One of the little tools I'm playing around with is just listing the number of files in all the directories / subdirectories of a selected Path. Since a path might contain several folders with approx. 30.000 larger files (8 MB each), I'm a bit worried about performance and would like to ask for review and advice:
- I'm using two backgroundworkers, the first of which is intended to proceed a total files count (incl. all the subdirs in the path) in order to set the maximum for a progress indicator:
total = My.Computer.FileSystem.GetFiles(PathName, FileIO.SearchOption.SearchAllSubDirectories).Count
- the second BW calls the function "zählung" which loops through the subdirs and updates the progress indicater through the _ProgressChanged event:
Private Sub Zählung(ByVal obj As String)<br />
Dim subfolders As System.Collections.ObjectModel.ReadOnlyCollection(Of String)<br />
Dim files As System.Collections.ObjectModel.ReadOnlyCollection(Of String)<br />
<br />
On Error Resume Next<br />
Me.Refresh()<br />
If BackgroundWorker2.CancellationPending Then Exit Sub<br />
<br />
If InStr(1, obj, "RECYCLER") > 0 Or InStr(1, obj, "System") > 0 Then<br />
'MsgBox(obj & " ist ein Systemordner", , USRINFO)<br />
Else<br />
If My.Computer.FileSystem.FileExists(obj & "\" & "Thumbs.db") Then<br />
My.Computer.FileSystem.DeleteFile(obj & "\" & "Thumbs.db")<br />
'MsgBox("Thumbs im Verzeichnis " & Pfad & " gelöscht!", MsgBoxStyle.Information, USRINFO)<br />
End If<br />
<br />
subfolders = My.Computer.FileSystem.GetDirectories(obj)<br />
files = My.Computer.FileSystem.GetFiles(obj, FileIO.SearchOption.SearchTopLevelOnly)<br />
ordner = ordner + subfolders.Count<br />
dateien = dateien + files.Count<br />
<br />
If total = Nothing Then<br />
'initially the progress indicator style has been set to marquee<br />
BackgroundWorker2.ReportProgress(dateien * 100 / dateien, obj)<br />
Else<br />
'progress indicator style has been set to continuous before, when BW1 is finished<br />
BackgroundWorker2.ReportProgress(dateien * 100 / total, obj)<br />
End If<br />
<br />
For Each unterordner As String In subfolders<br />
Zählung(unterordner)<br />
Next<br />
End If
During above function (i.e. ReportProgress) each path is also shown in a form label, and an additional timer-label (showing the time elapsed) is updated. How can I limit these updates to e.g. once per second?
After reading e.g. about "virtual listview" control, I really doubt that my methods are performing the best way they could. Would you be so kind and let me know any better performing ways?
Thank you very much
and have a nice day
Michael
|
|
|
|
|
Michael Schäuble wrote: total = My.Computer.FileSystem.GetFiles(PathName, FileIO.SearchOption.SearchAllSubDirectories).Count
That will create a list of strings that you just throw away, as you only use the size of the list. You should implement a method that loops the folders and counts the files, so that you don't create that huge list just to throw away.
Michael Schäuble wrote: During above function (i.e. ReportProgress) each path is also shown in a form label, and an additional timer-label (showing the time elapsed) is updated. How can I limit these updates to e.g. once per second?
Store the path in a variable, and use a timer to once a second put the current path and the elapsed time in the labels.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thank you, Guffa. Seems like I can really increase performance...
Which method would you think of? I'm pretty new to VB 2008 and didn't find any other method how to count the files yet, than listing their names and counting the number of names afterwards...
Regarding your 2nd hint: The path is stored in a variable (string), but the BackgroundWorker is called within every loop of the function and updates the labels. Which commands or structure would I need to limit that to once a second? How would I express something like "if now() = LastLabelUpdate + 1 then BGWorker.update" or so...??
|
|
|
|
|