![](/img/trans.png)
[英]What is the correct .Net method to decrypt an android AES encrypted file
[英]how to decrypt an encrypted audio file into the clipboard
我想知道是否有可能将加密的音频文件解密到剪贴板(而不是解密到新文件)中,然后播放。 我尝试编写一些代码,但是由于我对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
这样比较好,但是...如果我想播放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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.