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.
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.
// Install PGP-Crypt as a Cake Addin
#addin nuget:?package=PGP-Crypt&version=1.0.0

// Install PGP-Crypt as a Cake Tool
#tool nuget:?package=PGP-Crypt&version=1.0.0

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. 
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 230 11/12/2023