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 ::
Encryption ::
private void EncryptFile(string inputFile, string outputFile)
{
try
{
string password = @"myKey123";
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";
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();
}
}