Tools: String Manipulations Find Dupes My IP Json Formatter Lorem Ipsum More...
Discussion Options
ajax animation

C# .NET: Encrypt/Decrypt a Base64 String in .NET

11/23/2013 3:20:17 PM by: CodeLocker

Base64 Encoding is used to represent binary data in as ASCII string format. The following will take a string and either encrypt into a Base64 string or decrypt from a Base64 string.

It can also be used for very simple encryption. Never use it for data that needs to stay private.

View Copy: Content Copied
public static string EncryptBase64(string value)
{
	string result = "";

	try
	{
		if (!string.IsNullOrEmpty(value))
		{
			byte[] bytes = System.Text.UnicodeEncoding.UTF8.GetBytes(value);
			result = Convert.ToBase64String(bytes);
		}
	}
	catch{}

	return result;
}


public static string DecryptBase64(string value)
{
	string result = "";

	try
	{
		byte[] bytes = Convert.FromBase64String(value);

		result = System.Text.Encoding.UTF8.GetString(bytes);
	}
	catch{}

	return result;
}
Copy: Content Copied
ajax animation
×

Get Coding

Store your first code or add more code to your collection.
You must login to report abuse. ×