Posts

Showing posts with the label encrypt and decrypt

File Encryption and Decryption in C#

Introduction This article demonstrates how to use C# to encrypt and decrypt files of any type. Background Recently, I needed to find a simple way to encrypt and decrypt a file of any type (I actually needed to encrypt image and text files) and any size. I found hundreds of examples on the web, many of which just plain didn't work, or threw errors on certain file types. Eventually, I put together the following two methods using the Rijndael encryption algorithm. They simply require that you pass them the full path to the original and target files. They both require the use of the System.Security , System.Security.Cryptography , System.Runtime.InteropServices , and System.Text.RegularExpressions namespaces. Unfortunately, as I looked at so many examples on the web and actually did all this a while ago, I do not remember which bits of code were originally written by who. So, if you recognise some of it, many thanks, leave a comment below so that your work doesn't...

How to encrypt and decrypt a file by using Visual C#

This article describes how to use the cryptography classes that are provided by the Microsoft .NET Framework to encrypt a text file to an unreadable state, and then to decrypt that text file back to its original format. Requirements The following list outlines the recommended hardware, software, network infrastructure, and service packs that you must have: Microsoft Windows 2000 Professional, Windows 2000 Server, Windows 2000 Advanced Server, Windows NT 4.0 Server or Microsoft Windows XP Professional Microsoft Visual Studio 2005 or Microsoft Visual Studio .NET Encryption and decryption The System.Security.Cryptographic namespace in the Microsoft .NET Framework provides a variety of tools to help you with encryption and with decryption. The CryptoStream class is one of the many classes that is provided. The CryptoStream class is designed to encrypt or to decrypt content as it is streamed out to a file. Encrypt a file To encrypt a file, follow these steps: Start V...