如何将加密的音频文件解密到剪贴板中

时间:2016-02-16 04:12:34

标签: vb.net audio encryption

我想知道是否可以解密到剪贴板(而不是新文件)加密的音频文件,然后播放它。我曾尝试编写一些代码,但由于我对visual basic的了解不足,因此存在错误。我在Google上搜索过,但似乎有关加密音频文件的信息并不多。有谁可以帮助我吗? 我发布了代码:

Imports System.Security.Cryptography
Imports System.IO
Imports System.Text

Public Class Form1

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As   System.EventArgs) Handles Button2.Click
    Dim rij As New RijndaelManaged()
    rij.IV = New [Byte]() {2, 23, 35, 83, 7, 35, 28, 34, 94, 25, 45, 2, 73, 26, 27, 78}
    Dim pwd As Byte() = New Byte(14) {}
    UTF8Encoding.UTF8.GetBytes("123abc").CopyTo(pwd, 0)

    'Up to this point is working

    My.Computer.Clipboard.Clear()

    Dim cs As New CryptoStream(File.OpenRead("C:\Users\User\Desktop\bbb.wav"),
  rij.CreateDecryptor(pwd, rij.IV), CryptoStreamMode.Read)

    Dim ms As MemoryStream = New MemoryStream()
    cs.CopyTo(ms)

    GetStreamAsByteArray(ms)

    My.Computer.Clipboard.SetAudio(ms)
    If My.Computer.Clipboard.ContainsAudio Then
        My.Computer.Audio.Play(ms, AudioPlayMode.Background)
    End If

    End Sub

Private Function GetStreamAsByteArray(ByVal stream As MemoryStream) As Byte()
    Dim streamLength As Integer = Convert.ToInt32(stream.Length)
    Dim fileData As Byte() = New Byte(streamLength) {}
    stream.Read(fileData, 0, streamLength)
    stream.Flush()
    stream.Close()
    Return stream.ToArray()
End Function

End Class

1 个答案:

答案 0 :(得分:0)

这样更好,但是......如果我想播放mp3音频文件......没有机会?

Clipboard.Clear()            'clear the clipboard
    Clipboard.SetAudio(mp3Bytes) 'set the mp3 audio file bytes to the clipboard
    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

        'Now I would like to play the mp3 audio file (just decrypted) by getting the audio file bytes from the clipboard

        AxWindowsMediaPlayer1.Ctlcontrols.play() ' ???? I don't know how to go on

    End If