Click here to Skip to main content
16,017,922 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have written below code to do the encryption and decryption but i am not getting any output pl suggest

What I have tried:

namespace File_Encryption
{
	class AES
	{
		public static void Main(String[] args)
		{
		  }
		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(Exception E)
		    {		       
		    }
		}
		///<summary>
		/// Steve Lydford - 12/05/2008.
		///
		/// Decrypts a file using Rijndael algorithm.
		///</summary>
		///<param name="inputFile"></param>
		///<param name="outputFile"></param>
		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 4-May-18 1:39am
Comments
F-ES Sitecore 4-May-18 6:51am    
Remove your catch block then run the code again
Member 13777104 4-May-18 6:58am    
I have removed try catch blocks but still i am unable to get the command prompt output

1 solution

C#
public static void Main(String[] args)
{
  }

Your Main method is empty, so your program does nothing (exactly as you have coded it).
 
Share this answer
 
Comments
Member 13777104 4-May-18 7:43am    
YES I HAVE CHECKED IT MY DEBUGGING THE CODE , I AM NOT GETTING WHAT TO DO WHERE I NEED TO CHANGE IN THE ABOVE, CAN YOU PLEASE HELP,THANK YOU
Richard MacCutchan 4-May-18 7:52am    
You need to call the encrypt and decrypt methods with the appropriate parameters as you have defined them.

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