PGP-Crypt 1.0.0

dotnet add package PGP-Crypt --version 1.0.0
                    
NuGet\Install-Package PGP-Crypt -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PGP-Crypt" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PGP-Crypt" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="PGP-Crypt" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PGP-Crypt --version 1.0.0
                    
#r "nuget: PGP-Crypt, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PGP-Crypt@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PGP-Crypt&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=PGP-Crypt&version=1.0.0
                    
Install as a Cake Tool

PGP Encryption and Decryption in C#

Introduction

This C# implementation provides a simple yet robust solution for Pretty Good Privacy (PGP) encryption and decryption. The utility is designed to handle the encryption of plaintext data using a specified PGP public key and the subsequent decryption of PGP-encrypted data using a corresponding private key.

Dependencies

Features

  • Encryption: Securely encrypt plaintext data with a specified PGP public key.
  • Decryption: Safely decrypt PGP-encrypted data using the corresponding private key.
  • Key Handling: Obtain PGP public and private keys from armored files (e.g., .asc files).
  • Base64 Conversion: Easily convert encrypted data to and from Base64 format.

Usage

Encrypt Data

string contentToEncrypt = "Your sensitive data here";
string pathToPublicKey = "path/to/public/key.asc";
string encryptedData = PgpHelper.EncryptData(contentToEncrypt, pathToPublicKey);

// Use or transmit the 'encryptedData' as needed.

Decrypt Data

string pathToPrivateKey = "path/to/private/key.asc";
string privateKeyPassphrase = "YourPrivateKeyPassphrase";
string encryptedDataToDecrypt = "Base64-encoded PGP-encrypted data";

string decryptedData = PgpHelper.DecryptData(pathToPrivateKey, privateKeyPassphrase, encryptedDataToDecrypt);

// Use or process the 'decryptedData' as required.

How to Obtain PGP Keys

To use this utility, you'll need PGP public and private keys in armored format (e.g., .asc files).

Get PGP Public Key

string pathToPublicKey = "path/to/public/key.asc";
var publicKey = PgpHelper.GetPgpPubKey(pathToPublicKey);

// Use the 'publicKey' as needed.

Get PGP Private Key

string pathToPrivateKey = "path/to/private/key.asc";
string privateKeyPassphrase = "YourPrivateKeyPassphrase";
var privateKey = PgpHelper.GetPgpPrivateKey(pathToPrivateKey, privateKeyPassphrase);

// Use the 'privateKey' for decryption.

Example

// Example: Encrypting and Decrypting Data

string contentToEncrypt = "Top Secret Information";
string pathToPublicKey = "path/to/public/key.asc";
string pathToPrivateKey = "path/to/private/key.asc";
string privateKeyPassphrase = "YourPrivateKeyPassphrase";

// Encrypt data
string encryptedData = PgpHelper.EncryptData(contentToEncrypt, pathToPublicKey);

// Decrypt data
string decryptedData = PgpHelper.DecryptData(pathToPrivateKey, privateKeyPassphrase, encryptedData);

// Use or process 'encryptedData' and 'decryptedData' as required.

Notes

  • Ensure you have the Bouncy Castle Crypto Library referenced in your project.
  • Handle private keys and passphrases with care to maintain security.

Feel free to incorporate and modify this code in your project, adhering to the licensing terms of the Bouncy Castle Crypto Library.

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 670 11/12/2023