Click here to Skip to main content
16,016,263 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi i am yogesh sharma. i m creating a windows forms application in C# in which user can play pre added .mp3 or .wav files only through my application, that means if user copies it from my application folder and tries to play it from oustside. it fails to play...

For that i want to use encryption and decryption of files. for this process i will add encrypted files to my software folder, but for playing that encrypted files i must decrypt it, which i had successfully done using (Rijndael algorithm.) Now,

My Problem is that how can i hide those decrypted files which is necessary decrypt before playing... please help me or suggest some idea for the same...
please provide some help with code or example... any help will be appreciated...

My encryption/decryption code is as follows ::

C#
Encryption ::
private void EncryptFile(string inputFile, string outputFile)
        {
            try
            {
                string password = @"myKey123"; // Your Key Here
                UnicodeEncoding UE = new UnicodeEncoding();
                byte[] key = UE.GetBytes(password);

                string cryptFile = outputFile;
                FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);

                RijndaelManaged RMCrypto = new RijndaelManaged();

                CryptoStream cs = new CryptoStream(fsCrypt,
                    RMCrypto.CreateEncryptor(key, key),
                    CryptoStreamMode.Write);

                FileStream fsIn = new FileStream(inputFile, FileMode.Open);

                int data;
                while ((data = fsIn.ReadByte()) != -1)
                    cs.WriteByte((byte)data);


                fsIn.Close();
                cs.Close();
                fsCrypt.Close();
            }
            catch
            {
                MessageBox.Show("Encryption failed!", "Error");
            }
        }


Decryption ::

private void DecryptFile(string inputFile, string outputFile)
        {

            {
                string password = @"myKey123"; // Your Key Here

                UnicodeEncoding UE = new UnicodeEncoding();
                byte[] key = UE.GetBytes(password);

                FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);

                RijndaelManaged RMCrypto = new RijndaelManaged();

                CryptoStream cs = new CryptoStream(fsCrypt,
                    RMCrypto.CreateDecryptor(key, key),
                    CryptoStreamMode.Read);

                FileStream fsOut = new FileStream(outputFile, FileMode.Create);

                int data;
                while ((data = cs.ReadByte()) != -1)
                    fsOut.WriteByte((byte)data);

                fsOut.Close();
                cs.Close();
                fsCrypt.Close();

            }
        }
Posted
Updated 6-Mar-16 11:52am
v2

1 solution

Simple: don't store it as a file and play it from the file - you need to put the player into your application, and play it from the decrypted stream directly.
There is an example of playing from a stream here: http://stackoverflow.com/questions/6340967/play-wav-mp3-from-memory[^]
 
Share this answer
 
Comments
CPallini 22-Aug-15 12:08pm    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900