codice:
Imports System.Security.Cryptography
Imports System.IO
Imports System.Text
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rij As New RijndaelManaged()
rij.KeySize = 256
rij.BlockSize = 256
rij.IV = New [Byte]() {24, 23, 35, 83, 77, 35, 28, 34, 94, 25, 45, 2, 73, 26, 27, 78, 12, 23, 35, 83, 57, 35, 28, 34, 94, 25,
45, 22, 73, 26, 27, 78}
Dim pwd As Byte() = New Byte(31) {}
UTF8Encoding.UTF8.GetBytes("123abc").CopyTo(pwd, 0)
Dim cs As New CryptoStream(File.OpenRead("C:\Users\User\Desktop\aa.mp3"),
rij.CreateEncryptor(pwd, rij.IV), CryptoStreamMode.Read)
Dim s As Stream = File.OpenWrite("C:\Users\User\Desktop\bb.mp3")
cs.CopyTo(s)
s.Flush()
s.Close()
cs.Close()
Label1.Text = "Criptato!"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim rij As New RijndaelManaged()
rij.KeySize = 256
rij.BlockSize = 256
rij.IV = New [Byte]() {24, 23, 35, 83, 77, 35, 28, 34, 94, 25, 45, 2, 73, 26, 27, 78, 12, 23, 35, 83, 57, 35, 28, 34, 94, 25,
45, 22, 73, 26, 27, 78}
Dim pwd As Byte() = New Byte(31) {}
UTF8Encoding.UTF8.GetBytes("123abc").CopyTo(pwd, 0)
Dim mp3Bytes() As Byte
Using cs As New CryptoStream(File.OpenRead("C:\Users\User\Desktop\bb.mp3"), rij.CreateDecryptor(pwd, rij.IV),
CryptoStreamMode.Read)
Using ms As New MemoryStream
cs.CopyTo(ms)
mp3Bytes = ms.GetBuffer
End Using
End Using
Label1.Text = "Decriptato!"
Clipboard.Clear()
Clipboard.SetAudio(mp3Bytes)
If Clipboard.ContainsAudio Then
Dim btsFromClipboard() As Byte = {}
Using cbstrm As Stream = Clipboard.GetAudioStream
ReDim btsFromClipboard(CInt(cbstrm.Length) - 1)
cbstrm.Read(btsFromClipboard, 0, CInt(cbstrm.Length))
End Using
'Orra vorrei farlo suonare direttamente dalla clipboard
AxWindowsMediaPlayer1.Ctlcontrols.play() ' ???? Come si potrebbe risolvere?
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End
End Sub
End Class