Please i need help on how to encrypt a multimedia file with vb.net, for example, a flash file
This will encrypt & Decrypt. I set the extension to (.fla) flash file. It can be changed to your desired extension :
*Create an button called "Encrypt"
'This creates a folder on desktop if it doesn't exist on your desktop
If Not Directory.Exists($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\Encrypted") Then
Directory.CreateDirectory($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\Encrypted")
End If
If Not Directory.Exists($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\Decrypted") Then
Directory.CreateDirectory($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\Decrypted")
End If
'Creates a File Dialog Box to select the source file
Dim rythorian As New OpenFileDialog
Dim protocol As String
'If Encrypt Button is Click just select a file and click ok after
If rythorian.ShowDialog() = DialogResult.OK Then
protocol = rythorian.FileName
For Each path In rythorian.FileName
Dim outputFile As String
Dim prata As String = rythorian.FileName
'This creates a folder on your desktop with file in it.
'Change the extension from .txt to flash (FLA)
outputFile = My.Computer.FileSystem.SpecialDirectories.Desktop & "\Encrypted\Encrypted.fla" '<<<<<<<<<<<<<<<<<<
Dim fsInput As New FileStream(prata, FileMode.Open, FileAccess.Read)
Dim fsEncrypted As New FileStream(outputFile, FileMode.Create, FileAccess.Write)
Dim sKey As String
sKey = "Helloabc"
Dim DES As New DESCryptoServiceProvider With {
.Key = Encoding.ASCII.GetBytes(sKey),
.IV = Encoding.ASCII.GetBytes(sKey)
}
Dim desencrypt As ICryptoTransform
desencrypt = DES.CreateEncryptor()
Dim cryptostream As New CryptoStream(fsEncrypted, desencrypt, CryptoStreamMode.Write)
Dim bytearrayinput(fsInput.Length) As Byte
fsInput.Read(bytearrayinput, 0, bytearrayinput.Length)
cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length)
cryptostream.Close()
fsInput.Close()
fsEncrypted.Close()
'Change the extension to whatever you want
prata = My.Computer.FileSystem.SpecialDirectories.Desktop & "\Encrypted\Encrypted.fla" '<<<<<<<<<<
Next
Dim fileToDel As String
fileToDel = rythorian.FileName
Kill(fileToDel)
End If
Create a button called "Decrypt"
'This creates a folder on desktop if it doesn't exist
If Not Directory.Exists($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\Encrypted") Then
Directory.CreateDirectory($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\Encrypted")
End If
If Not Directory.Exists($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\Decrypted") Then
Directory.CreateDirectory($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\Decrypted")
End If
'Creates a File Dialog Box to select the source file
Dim rythorian As New OpenFileDialog
Dim protocol As String
'If Decrypt Button is Click just select a file and click ok after.
If rythorian.ShowDialog() = DialogResult.OK Then
protocol = rythorian.FileName
For Each path In rythorian.FileName
Dim DES As New DESCryptoServiceProvider
Dim sKey As String
Dim stata As String = rythorian.FileName
sKey = "Helloabc"
DES.Key = Encoding.ASCII.GetBytes(sKey)
DES.IV = Encoding.ASCII.GetBytes(sKey)
Dim fsread As New FileStream(stata, FileMode.Open, FileAccess.Read)
Dim desdecrypt As ICryptoTransform
desdecrypt = DES.CreateDecryptor()
Dim cryptostreamDecr As New CryptoStream(fsread, desdecrypt, CryptoStreamMode.Read)
'This creates a folder on your desktop with file in it.
'Change the extension to whatever you want
Dim fsDecrypted As New StreamWriter(My.Computer.FileSystem.SpecialDirectories.Desktop & "\Decrypted\Decrypted.fla")
fsDecrypted.Write(New StreamReader(cryptostreamDecr).ReadToEnd())
fsDecrypted.Flush()
fsDecrypted.Close()
'Change the extension to whatever
stata = My.Computer.FileSystem.SpecialDirectories.Desktop & "\Decrypted\Decrypted.fla" '<<<<<<<<<
Next
End If