how to convert a binary array to .wav with c#? - c#

I'm doing a project in C# which requires me to encrypt a wave file. So, is there a straight forward process to convert a wave file into binary and back? I'll be applying an encryption algorithm on the binary data.

Sure, checkout the File.ReadAllBytes and File.WriteAllBytes methods. Or if the files are too large to fit in memory you could read/write in blocks using a FileStream.

You can use FileStream to read a binary file, such as WAV file and then another FileStream to write the encrypted version back out.
You need to read and write the files in blocks using a byte array.

Related

How to write byte of array to PDF/A-3 and attachment in C# / Vb.net [Close]

I want to convert PDF to PDF/a-3 as byte[] and file attachment .
I've tried iTextSharp from these example PDF/AConvert.NET
But the problem is i can't use File.WriteAllBytes() on my scenario because i have to avoid to write a File on directory.
In another way i have pdfData as byte Array how can i write it to pdf/a-3
it would be great if there are other solution,
Please help.
You don't need to write a physical file using a FileStream; you can use a MemoryStream to write directly to memory, and then use that as your stream.
FileStream and MemoryStream are both derived from Stream.

How to identify the binary compression type from the content?

I am trying to restore files which are stored in MS SQL database (used by third party application which has stopped their support) as an image data type(byte arrays). So what I do is to write those rows of byte arrays to file to convert for know file extensions. However some of them are not known which I believe they are compressed. Since I get "CC_Compress" string and random characters in the file after conversion. I was wondering if it is possible to find out which compression method were used and how can I decompress it before I convert them.
Following is first bytes from the byte array:
0x43435F434F4D50524553530000000000000000000000010004F60000E4780000EC7C075C54C7F3F85CA10A8A204544796001519A0D4569414414011115238A079C80C21D5204224D632C51C19268628FC6A851638B9A88882D9604C5D83BB688A002564085FBCFBEBDC71DCD16623EFFEF2FA373B33B5B667676B6BC7DCB3B9DDFF2E677DB8D6F411D70060154CB34401514C043D4E5223A00AD80F2AA65321961B54494FD07FF5FC1C3750741304E430850A19B0B2CE8B0BFD8F16DD5019A43C88490097FC4FD1107F5404368003D740036B6E6B1D816DE0C32598BB78639F89EFDDD20801AAA1C6E8CB60205E
and 43435F434F4D5052455353 is the part that converts to CC_Compress
Thanks in advance,
Raw deflate-compressed data begins 32 bytes in (starting with the ec 7c). You can use zlib to decompress it.

Buffering stream of byte array

I am using DropNet library to download files from Dropbox.
public Stream GetFileStream(string path)
{
return new MemoryStream(dropboxClient.GetFile(path));
}
I am facing a problem in downloading large files because DropNet library returns byte array then I convert that byte array to stream for another logical purposes using MemoryStream which is not good because I have to download files to server memory then complete my logic
I am trying to find a way to buffer that files as a stream.
I looked at BufferedStream Class but to create new buffersteam it requires a stream first. I can't figure the best solution for my problem.
The DropNet API does not expose a Stream functionality for retrieving files. You must wait for the entire file to be downloaded before you can use it. If you want to be able to read the stream as it comes in you will need to use a different library, modify an existing one, or write your own.

C# Save byte array as xml file

I'm receiving a .zip file from a server.
The .zip file is sent 64Base encoded and it contains an XML file.
After I decode the data to binary using Convert.FromBase64String, can I convert the byte array to XML?
I don't want to deal with unzipping.
I tried the following code: (that resulted in Gibberish that doesn't make any sense and doesn't look like XML at all)
XmlDocument doc = new XmlDocument();
string xml = Encoding.UTF8.GetString(buffer);
doc.LoadXml(xml);
Any ideas?
You say you don't want to unzip, but do you actually mean that you don't want to unzip to disc? Most zip libraries either allow you to unzip a file to a byte array directly or to a stream where you could pass it a MemoryStream.
There's no getting around having to uncompress. Unless you have control over the server side, then you could change the format to an uncompressed file (like a tar file). Then you wouldn't have to uncompress.
You say:
I'm receiving a .zip file from a server.
And:
I don't want to deal with unzipping.
Well. You have to. If the data is in a zip archive, you need to extract it first. You can't just ignore the fact.
There are plenty of zip libraries - sharpziplib is free and easy enough to use.

Create .wav file using C#

I have nessary chunk header bytes for a wave file stored in a text file. What I'd like to do is create a new .wav that will vary in data length and write into it 50ms/10kHz signals(which is stored in separate file). How can I accomplish with .NET/C#?
-Mickey
Use the System.IO.BinaryReader and System.IO.BinaryWriter streams to read data from your signals files, write binary datatypes to a file, as per the wav file specification.

Categories

Resources