App to Encrypt and Decrypt file public sealed class Class1
{
    Class1()
    {

    }
    private static readonly object padlock = new object();
    private static Class1 instance = null;
    public static Class1 Instance
    {
        get
        {
            if (instance == null)
            {
                lock (padlock)
                {
                    if (instance == null)
                    {
                        instance = new Class1();
                    }
                }
            }
            return instance;
        }
    }

    public bool EncryptFile(string path)
    {
        string ext = Path.GetExtension(path).Replace(".","");
        string filename = Path.GetFileNameWithoutExtension(path);

        byte[] b= System.Text.ASCIIEncoding.ASCII.GetBytes(ext);
        string encrypted = Convert.ToBase64String(b);
        var newPath = path.Replace(filename+"."+ext, filename+"_"+ encrypted + ".vik");

        try
        {
            string password = @"vik12389"; // Your Key Here
            UnicodeEncoding UE = new UnicodeEncoding();
            byte[] key = UE.GetBytes(password);

            string cryptFile = newPath;
            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(path, FileMode.Open);

            int data;
            while ((data = fsIn.ReadByte()) != -1)
                cs.WriteByte((byte)data);
            fsIn.Close();
            cs.Close();
            fsCrypt.Close();
            File.Delete(path);

            return true;

        }
        catch(Exception e)
        {
            return false;
        }
    }

    public bool DecryptFile(string path)
    {
        string ext = Path.GetExtension(path).Replace(".", "");
        string filename = Path.GetFileNameWithoutExtension(path);

        string[] splitFilename = filename.Split('_');

        byte[] b = Convert.FromBase64String(splitFilename[1]);

        string decryptedfileext = System.Text.ASCIIEncoding.ASCII.GetString(b);

        var newPath = path.Replace(filename + ".vik", splitFilename[0] + '.'+ decryptedfileext);
        try
        {
            string password = @"vik12389"; // Your Key Here

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


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

            RijndaelManaged RMCrypto = new RijndaelManaged();

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

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

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

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

            return true;

        }
        catch (Exception e)
        {
            return false;
        }

    }

}


My Project Link on GitHub :https://github.com/vivianm94/EncryptFile.
how do I improve my code any suggestion.any features that could be added to the project
So, the most interesting bits about this code are the wildly differing styles throughout. It seems as it's almost copy-and-pasted from several sources. The reason I bring this up is because consistency is a hallmark of clean and maintainable code. A few things I noticed:


There's a debunked use of "double-checked locking" to attempt to use a lazily-instantiated singleton. Two things with this: A. This class doesn't have state and could be static to begin with, and thus do not need to worry about instances at all, and B. There's a very easy way these days to have a lazy singleton: the Lazy&lt;T&gt; class. You'll see its usage below.
There's a mish-mash of ASCIIEncoding.ASCII and new UnicodeEncoding(). The canonical way to access predefined encodings is through static members of the Encoding class: Encoding.ASCII and Encoding.Unicode.
Path.Combine() is wisely used to, of course, combine paths. But then string concatenation is used to pop an extension on the file name. Path.ChangeExtension() exists for just this task.
x.Close() isn't needed if you wrap your IDisposable resources in using blocks. This also has the benefit of guaranteeing disposal/closing in the case of an exception (it's syntactic sugar for a try..finally construct`.
There's a mix of using and not using var for variable declarations. Since the latter is less than the former, standardize on just using the actual type name for declarations.
I added two more - you don't need to read/write the file byte by byte. These are streams for a reason, and .NET gives us a handy method CopyTo to take care of the details. Also, CreateEncrpytor and CreateDecryptor return IDisposable-implementing classes, so I extracted them into their own usings.


Putting all that together, the class now looks like (note that I went with Lazy&lt;T&gt; rather than static class):

public sealed class Class1
{
    private static readonly Lazy&lt;Class1&gt; instance = new Lazy&lt;Class1&gt;(() =&gt; new Class1());
    public static Class1 Instance =&gt; instance.Value;

    public bool EncryptFile(string path)
    {
        string ext = Path.GetExtension(path).Replace(".", string.Empty);
        string filename = Path.GetFileNameWithoutExtension(path);

        byte[] b = Encoding.ASCII.GetBytes(ext);
        string encrypted = Convert.ToBase64String(b);
        string newPath = path.Replace(Path.ChangeExtension(filename, ext), filename + "_" + encrypted + ".vik");

        try
        {
            string password = @"vik12389"; // Your Key Here
            byte[] key = Encoding.Unicode.GetBytes(password);

            string cryptFile = newPath;
            using (FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create))
            using (RijndaelManaged RMCrypto = new RijndaelManaged())
            using (ICryptoTransform ct = RMCrypto.CreateEncryptor(key, key))
            using (CryptoStream cs = new CryptoStream(fsCrypt,
                ct,
                CryptoStreamMode.Write))
            using (FileStream fsIn = new FileStream(path, FileMode.Open))
            {
                fsIn.CopyTo(cs);
            }

            File.Delete(path);

            return true;

        }
        catch(Exception e)
        {
            return false;
        }
    }

    public bool DecryptFile(string path)
    {
        string ext = Path.GetExtension(path).Replace(".", string.Empty);
        string filename = Path.GetFileNameWithoutExtension(path);

        string[] splitFilename = filename.Split('_');

        byte[] b = Convert.FromBase64String(splitFilename[1]);

        string decryptedfileext = Encoding.ASCII.GetString(b);

        string newPath = path.Replace(Path.ChangeExtension(filename, "vik"), splitFilename[0] + '.'+ decryptedfileext);
        try
        {
            string password = @"vik12389"; // Your Key Here

            byte[] key = Encoding.Unicode.GetBytes(password);

            using (FileStream fsCrypt = new FileStream(path, FileMode.Open))
            using (RijndaelManaged RMCrypto = new RijndaelManaged())
            using (ICryptoTransform ct = RMCrypto.CreateDecryptor(key, key))
            using (CryptoStream cs = new CryptoStream(fsCrypt,
                ct,
                CryptoStreamMode.Read))
            using (FileStream fsOut = new FileStream(newPath, FileMode.Create))
            {
                cs.CopyTo(fsOut);
            }

            return true;

        }
        catch (Exception e)
        {
            return false;
        }

    }

}