Below is a list of libraries that support Base64 encoding and decoding in C# along with sample code for each library.
1. .NET Standard Library
The .NET Standard Library provides the Convert
class with methods for Base64 encoding and decoding.
using System;
public class Base64Example
{
public static void Main(string[] args)
{
string originalString = "test input";
// Encode
string encodedString = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(originalString));
Console.WriteLine("Encoded: " + encodedString);
// Decode
string decodedString = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(encodedString));
Console.WriteLine("Decoded: " + decodedString);
}
}
2. Bouncy Castle
Bouncy Castle is a powerful encryption library that supports Base64 encoding and decoding.
using System;
using Org.BouncyCastle.Utilities.Encoders;
public class Base64Example
{
public static void Main(string[] args)
{
string originalString = "test input";
// Encode
string encodedString = Base64.ToBase64String(System.Text.Encoding.UTF8.GetBytes(originalString));
Console.WriteLine("Encoded: " + encodedString);
// Decode
string decodedString = System.Text.Encoding.UTF8.GetString(Base64.Decode(encodedString));
Console.WriteLine("Decoded: " + decodedString);
}
}
3. Microsoft.AspNetCore.WebUtilities
The Microsoft.AspNetCore.WebUtilities
namespace provides the WebEncoders
class for Base64Url encoding and decoding.
using System;
using Microsoft.AspNetCore.WebUtilities;
public class Base64Example
{
public static void Main(string[] args)
{
string originalString = "test input";
// Encode
string encodedString = WebEncoders.Base64UrlEncode(System.Text.Encoding.UTF8.GetBytes(originalString));
Console.WriteLine("Encoded: " + encodedString);
// Decode
string decodedString = System.Text.Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(encodedString));
Console.WriteLine("Decoded: " + decodedString);
}
}
4. Newtonsoft.Json (Json.NET)
Json.NET, commonly known as Newtonsoft.Json, also provides utilities for Base64 encoding and decoding as part of JSON serialization and deserialization.
using System;
using Newtonsoft.Json;
public class Base64Example
{
public static void Main(string[] args)
{
string originalString = "test input";
// Encode
string encodedString = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(originalString));
Console.WriteLine("Encoded: " + encodedString);
// Decode
string decodedString = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(encodedString));
Console.WriteLine("Decoded: " + decodedString);
}
}
Add the dependency to csproj
:
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
5. System.Security.Cryptography
The System.Security.Cryptography
namespace provides cryptographic services including encoding and decoding.
using System;
using System.Security.Cryptography;
using System.Text;
public class Base64Example
{
public static void Main(string[] args)
{
string originalString = "test input";
// Encode
byte[] plainTextBytes = Encoding.UTF8.GetBytes(originalString);
string encodedString = Convert.ToBase64String(plainTextBytes);
Console.WriteLine("Encoded: " + encodedString);
// Decode
byte[] base64EncodedBytes = Convert.FromBase64String(encodedString);
string decodedString = Encoding.UTF8.GetString(base64EncodedBytes);
Console.WriteLine("Decoded: " + decodedString);
}
}
Welcome to our Convert Base64 To Pdf C And Save File tool, the ultimate solution to Convert Base64 To Pdf C And Save File quickly and easily. Whether you need to convert binary data for safe transmission or storage, our tool provides a simple and efficient way to decode your data from Base64 format.
Why Use Base64 Encoding?
Base64 encoding is a method of converting binary data into a text format using 64 characters. This encoding scheme is especially useful when you need to transfer or store data over media designed to handle text, such as email or JSON files. Base64 ensures your data remains intact and unmodified during transport.
Key Features of Our Base64 Decoding Tool
Simple and Fast Decoding
Our tool makes it incredibly easy to Convert Base64 To Pdf C And Save File. Simply enter your data, click the "Decode" button, and get your Base64 decoded result instantly. No complex configurations or technical knowledge required.
Secure and Private
We prioritize your privacy and data security. All communications with our servers are encrypted using SSL connections. We do not store or inspect the contents of your decoded data, ensuring complete confidentiality.
Free to Use
Our Base64 decoding tool is completely free. You don’t need to download any software or register for an account. Access our online tool anytime, anywhere, without any cost.
Advanced Options
Character Set Selection
While Base64 encoding does not inherently include character set information, our tool allows you to specify the character set used during encoding. Commonly, UTF-8 is used, but other options are available. If unsure, try the auto-detect option for the best results.
Live Decoding Mode
Enable live mode to see your data decoded in real-time using your browser’s built-in JavaScript functions. This feature supports the UTF-8 character set and does not send data to our servers, offering enhanced privacy.
How to Convert Base64 To Pdf C And Save File
Follow these simple steps to Convert Base64 To Pdf C And Save File:
- Enter your data:Paste your text or binary data into the input field.
- Click "Decode":Hit the "Decode" button to convert your data from Base64 format.
- Copy the result:Your decoded data will appear instantly. Copy it for use in your applications.
Example of Base64 Decoding
Here’s a quick example. Decoding the Base64 string "SGVsbG8sIFdvcmxkIQ==" yields:
Hello, World!
In this example, the Base64 encoded string "SGVsbG8sIFdvcmxkIQ==" is decoded to "Hello, World!", providing a simple and efficient way to convert Base64 data back to its original text format.