### PgpCore Quick Start Example Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/README.md Demonstrates the basic workflow of generating PGP keys, encrypting a file, and decrypting it using PgpCore. Ensure you have the PgpCore package installed and the necessary file paths are correct. ```csharp using PgpCore; using System.IO; // Generate keys var pgp = new PGP(); await pgp.GenerateKeyAsync( new FileInfo("public.asc"), new FileInfo("private.asc"), username: "test@example.com", password: "password"); // Encrypt var keys = new EncryptionKeys(new FileInfo("public.asc")); var pgpWithKeys = new PGP(keys); await pgpWithKeys.EncryptAsync( new FileInfo("plaintext.txt"), new FileInfo("encrypted.pgp")); // Decrypt var keysForDecryption = new EncryptionKeys( new FileInfo("public.asc"), new FileInfo("private.asc"), "password"); var pgpForDecryption = new PGP(keysForDecryption); await pgpForDecryption.DecryptAsync( new FileInfo("encrypted.pgp"), new FileInfo("decrypted.txt")); ``` -------------------------------- ### Create Symmetric-Only Encryption Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/configuration.md Instantiate PGP with a symmetric key for symmetric-only encryption. This example shows the setup and initial encryption process. ```csharp // Create symmetric-only encryption byte[] symmetricKey = /* 32-byte key */; var keys = new EncryptionKeys(symmetricKey); var pgp = new PGP(keys); await pgp.EncryptAsync(inputFile, outputFile); ``` -------------------------------- ### Quick Encryption Example Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/INDEX.md Demonstrates how to perform a quick file encryption using PGP. Ensure you have the public key file and the plaintext file available. ```csharp using PgpCore; // Load public key var keys = new EncryptionKeys(new FileInfo("public.asc")); var pgp = new PGP(keys); // Encrypt file await pgp.EncryptAsync( new FileInfo("plaintext.txt"), new FileInfo("encrypted.pgp")); ``` -------------------------------- ### PGPCore Add Version Header Property Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets whether to include version header information in armored output. Default is `true`. Example shows disabling the version header. ```csharp public bool AddVersionHeader { get; set; } ``` ```csharp pgp.AddVersionHeader = false; ``` -------------------------------- ### PGPCore File Type Property Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets the file type used for literal data packets. Default is `Binary`. Example shows setting the file type to UTF8. ```csharp public PGPFileType FileType { get; set; } ``` ```csharp pgp.FileType = PGPFileType.UTF8; ``` -------------------------------- ### PGPCore Public Key Algorithm Property Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets the public key algorithm. Default is `RsaGeneral`. ```csharp public PublicKeyAlgorithmTag PublicKeyAlgorithm { get; set; } ``` -------------------------------- ### Access PGP Message Version Header Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/models.md Provides an example of accessing the 'Version' header from a PGP message. ```csharp if (!string.IsNullOrEmpty(result.Version)) { Console.WriteLine($"Created by: {result.Version}"); } ``` -------------------------------- ### PGPCore Compression Algorithm Property Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets the compression algorithm used for encryption operations. Default is `Uncompressed`. ```csharp public CompressionAlgorithmTag CompressionAlgorithm { get; set; } ``` -------------------------------- ### Polymorphic Key Handling with IEncryptionKeys Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/interfaces.md Manage and interact with encryption keys polymorphically using the IEncryptionKeys interface. This example shows configuring encryption and retrieving key IDs. ```csharp public class KeyManager { private readonly IEncryptionKeys keys; public void ConfigureEncryption(long preferredKeyId) { foreach (var ring in keys.PublicKeyRings) { ring.UsePreferredEncryptionKey(preferredKeyId); } } public IEnumerable GetAvailableKeyIds() { return keys.EncryptKeys.Select(k => k.KeyId); } } ``` -------------------------------- ### Composite Operations with IPGP Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/interfaces.md Utilize the IPGP interface for composite operations that may involve multiple steps like encryption and signing. This example demonstrates an asynchronous encrypt and sign operation. ```csharp // For composite operations IPGP cryptography = new PGP(keys); await cryptography.EncryptAndSignAsync(input, output); ``` -------------------------------- ### Initialize EncryptionKeys with Public Key Files and Private Key File Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Use this constructor when you have multiple public key files and one private key file. Ensure all specified files exist and the passphrase is correct. ```csharp public EncryptionKeys( IEnumerable publicKeyFiles, FileInfo privateKeyFile, string passPhrase) ``` ```csharp var publicKeyFiles = new[] { new FileInfo("public1.asc"), new FileInfo("public2.asc") }; var keys = new EncryptionKeys(publicKeyFiles, privateKeyFile, "password"); ``` -------------------------------- ### PGPCore PGP Signature Type Property Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets the PGP signature type. Default is `PgpSignature.DefaultCertification`. Example shows setting the signature type to BinaryDocument. ```csharp public int PgpSignatureType { get; set; } ``` ```csharp pgp.PgpSignatureType = PgpSignature.BinaryDocument; ``` -------------------------------- ### EncryptionKeys(IEnumerable publicKeyFiles, FileInfo privateKeyFile, string passPhrase) Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initializes a new instance with multiple public key files and a single private key file. ```APIDOC ## EncryptionKeys(IEnumerable publicKeyFiles, FileInfo privateKeyFile, string passPhrase) ### Description Initializes a new instance with multiple public key files and a single private key file. ### Parameters #### Path Parameters - **publicKeyFiles** (IEnumerable) - Required - Collection of public key file paths - **privateKeyFile** (FileInfo) - Required - Path to private key file - **passPhrase** (string) - Required - Passphrase to decrypt the private key ### Request Example ```csharp var publicKeyFiles = new[] { new FileInfo("public1.asc"), new FileInfo("public2.asc") }; var keys = new EncryptionKeys(publicKeyFiles, privateKeyFile, "password"); ``` ### Throws: `ArgumentException`, `FileNotFoundException`, `PgpException` ``` -------------------------------- ### PGPCore Hash Algorithm Tag Property Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets the hash algorithm used for signatures. Default is `Sha1`. Example shows setting the hash algorithm to SHA256. ```csharp public HashAlgorithmTag HashAlgorithmTag { get; set; } ``` ```csharp pgp.HashAlgorithmTag = HashAlgorithmTag.Sha256; ``` -------------------------------- ### Initialize EncryptionKeys with Multiple Public Key Files Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Use this constructor to initialize with multiple public keys from files. It supports encryption and verification. ```csharp public EncryptionKeys(IEnumerable publicKeyFiles) ``` ```csharp var publicKeyFiles = new[] { new FileInfo("public1.asc"), new FileInfo("public2.asc") }; var keys = new EncryptionKeys(publicKeyFiles); ``` -------------------------------- ### PGPCore Symmetric Key Algorithm Property Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets the symmetric key algorithm used for encryption. Default is `TripleDes`. Example shows setting the algorithm to AES256. ```csharp public SymmetricKeyAlgorithmTag SymmetricKeyAlgorithm { get; set; } ``` ```csharp pgp.SymmetricKeyAlgorithm = SymmetricKeyAlgorithmTag.Aes256; ``` -------------------------------- ### Initialize EncryptionKeys with Public Key File Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Use this constructor to initialize with a public key from a file. It's intended for encryption and verification tasks. ```csharp public EncryptionKeys(FileInfo publicKeyFile) ``` ```csharp var keys = new EncryptionKeys(new FileInfo("public.asc")); ``` -------------------------------- ### Initialize EncryptionKeys with Public Key String Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initialize an instance with a single public key provided as a PGP-encoded string. This is suitable for encryption and verification purposes only. ```csharp public EncryptionKeys(string publicKey) ``` ```csharp var keys = new EncryptionKeys(publicKeyStr); ``` -------------------------------- ### EncryptionKeys Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets the encryption keys used for cryptographic operations. ```APIDOC ## EncryptionKeys ### Description Gets or sets the encryption keys used for cryptographic operations. ``` -------------------------------- ### Initialize EncryptionKeys with File Keys and Raw Byte Passphrase Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Use this constructor when your public and private keys are in files and you need to provide the passphrase as raw byte data. This offers a secure way to handle passphrase input when keys are file-based. ```csharp public EncryptionKeys( FileInfo publicKeyFile, FileInfo privateKeyFile, byte[] rawPassPhrase) ``` -------------------------------- ### EncryptionKeys(FileInfo privateKeyFile, string passPhrase) Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initializes a new instance with only a private key file (for signing/decryption only). ```APIDOC ## EncryptionKeys(FileInfo privateKeyFile, string passPhrase) ### Description Initializes a new instance with only a private key file (for signing/decryption only). ### Parameters #### Path Parameters - **privateKeyFile** (FileInfo) - Required - Path to private key file - **passPhrase** (string) - Required - Passphrase to decrypt the private key ### Request Example ```csharp var keys = new EncryptionKeys(new FileInfo("private.asc"), "password"); ``` ### Throws: `ArgumentException`, `FileNotFoundException`, `PgpException` ``` -------------------------------- ### PublicKeyAlgorithm Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets the public key algorithm. Default is `RsaGeneral`. ```APIDOC ## PublicKeyAlgorithm ### Description Gets or sets the public key algorithm. Default is `RsaGeneral`. ### Valid values `RsaGeneral`, `RsaSign`, `Dsa`, `ECDH`, `ECDsa`, `ElGamalGeneral`, `ElGamalEncrypt`, `DiffieHellman`, `EdDsa` ``` -------------------------------- ### PgpSignatureType Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets the PGP signature type. Default is `PgpSignature.DefaultCertification`. ```APIDOC ## PgpSignatureType ### Description Gets or sets the PGP signature type. Default is `PgpSignature.DefaultCertification`. ### Example ```csharp pgp.PgpSignatureType = PgpSignature.BinaryDocument; ``` ``` -------------------------------- ### Initialize EncryptionKeys with File Keys and String Passphrase Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Use this constructor when your public and private keys are stored in separate files and you have the passphrase as a string. This is convenient for managing keys stored on disk. ```csharp public EncryptionKeys( FileInfo publicKeyFile, FileInfo privateKeyFile, string passPhrase) ``` ```csharp var keys = new EncryptionKeys( new FileInfo("public.asc"), new FileInfo("private.asc"), "password"); ``` -------------------------------- ### HashAlgorithmTag Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets the hash algorithm used for signatures. Default is `Sha1`. ```APIDOC ## HashAlgorithmTag ### Description Gets or sets the hash algorithm used for signatures. Default is `Sha1`. ### Valid values `MD2`, `MD5`, `RipeMD160`, `Sha1`, `Sha224`, `Sha256`, `Sha384`, `Sha512` ### Example ```csharp pgp.HashAlgorithmTag = HashAlgorithmTag.Sha256; ``` ``` -------------------------------- ### Initialize EncryptionKeys with Multiple Public Key Strings Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initialize an instance with multiple public keys provided as an enumerable collection of PGP-encoded strings. This is for encryption and verification. ```csharp public EncryptionKeys(IEnumerable publicKeys) ``` ```csharp var publicKeysStr = new[] { pubKey1, pubKey2 }; var keys = new EncryptionKeys(publicKeysStr); ``` -------------------------------- ### Initialize EncryptionKeys with Private Key File Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Use this constructor to initialize EncryptionKeys with a private key file. This is suitable for signing and decryption operations when the key is stored in a file. ```csharp public EncryptionKeys( FileInfo privateKeyFile, string passPhrase) ``` ```csharp var keys = new EncryptionKeys(new FileInfo("private.asc"), "password"); ``` -------------------------------- ### SymmetricKeyAlgorithm Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets the symmetric key algorithm used for encryption. Default is `TripleDes`. ```APIDOC ## SymmetricKeyAlgorithm ### Description Gets or sets the symmetric key algorithm used for encryption. Default is `TripleDes`. ### Valid values `TripleDes`, `Idea`, `Cast5`, `Blowfish`, `Aes128`, `Aes192`, `Aes256`, `Twofish`, `Camellia128`, `Camellia192`, `Camellia256` ### Example ```csharp pgp.SymmetricKeyAlgorithm = SymmetricKeyAlgorithmTag.Aes256; ``` ``` -------------------------------- ### Initialize EncryptionKeys with String Keys and String Passphrase Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Use this constructor when your public and private keys are available as PGP-encoded strings and you have the passphrase as a string. Ensure keys are correctly formatted. ```csharp public EncryptionKeys( string publicKey, string privateKey, string passPhrase) ``` ```csharp string publicKeyStr = File.ReadAllText("public.asc"); string privateKeyStr = File.ReadAllText("private.asc"); var keys = new EncryptionKeys(publicKeyStr, privateKeyStr, "password"); ``` -------------------------------- ### CompressionAlgorithm Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets the compression algorithm used for encryption operations. Default is `Uncompressed`. ```APIDOC ## CompressionAlgorithm ### Description Gets or sets the compression algorithm used for encryption operations. Default is `Uncompressed`. ### Valid values `Uncompressed`, `Zip`, `BZip2`, `Zlib` ``` -------------------------------- ### FileType Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets the file type used for literal data packets. Default is `Binary`. ```APIDOC ## FileType ### Description Gets or sets the file type used for literal data packets. Default is `Binary`. ### Valid values `Binary`, `Text`, `UTF8` ### Example ```csharp pgp.FileType = PGPFileType.UTF8; ``` ``` -------------------------------- ### Initialize EncryptionKeys with Multiple Public Key Streams and Private Key Stream Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Use this constructor when you have multiple public key streams and a single private key stream. This allows for flexible loading of keys from various stream sources. ```csharp public EncryptionKeys( IEnumerable publicKeyStreams, Stream privateKeyStream, string passPhrase) ``` -------------------------------- ### PGPCore Encryption Keys Property Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets the encryption keys used for cryptographic operations. ```csharp public IEncryptionKeys EncryptionKeys { get; private set; } ``` -------------------------------- ### EncryptionKeys(IEnumerable publicKeyFiles) Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initializes a new instance with multiple public key files, specified as a collection of FileInfo objects. This constructor is for encryption and verification using several public key files. ```APIDOC ## EncryptionKeys(IEnumerable publicKeyFiles) ### Description Initializes a new instance with multiple public key files (for encryption/verification only). ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **publicKeyFiles** (IEnumerable) - Required - Collection of public key file paths ### Request Example ```csharp var publicKeyFiles = new[] { new FileInfo("public1.asc"), new FileInfo("public2.asc") }; var keys = new EncryptionKeys(publicKeyFiles); ``` ### Response #### Success Response (200) - None explicitly documented. #### Response Example - None explicitly documented. ``` -------------------------------- ### SigningPrivateKey Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Gets the private key used for signing operations. This is essential for creating digital signatures. ```APIDOC ## SigningPrivateKey ### Description Gets the private key used for signing operations. ### Returns `PgpPrivateKey` - The private key, or null if no private key is loaded. ### Example ```csharp if (encryptionKeys.SigningPrivateKey != null) { // Can sign } ``` ``` -------------------------------- ### EncryptionKeys(FileInfo publicKeyFile) Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initializes a new instance with only a public key from a file, intended for encryption and verification. The file path should point to the PGP public key file. ```APIDOC ## EncryptionKeys(FileInfo publicKeyFile) ### Description Initializes a new instance with only a public key file (for encryption/verification only). ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **publicKeyFile** (FileInfo) - Required - Path to public key file ### Request Example ```csharp var keys = new EncryptionKeys(new FileInfo("public.asc")); ``` ### Response #### Success Response (200) - None explicitly documented. #### Response Example - None explicitly documented. ``` -------------------------------- ### AddVersionHeader Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Gets or sets whether to include version header information in armored output. Default is `true`. ```APIDOC ## AddVersionHeader ### Description Gets or sets whether to include version header information in armored output. Default is `true`. ### Example ```csharp pgp.AddVersionHeader = false; ``` ``` -------------------------------- ### Create PGP Instance with Keys Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Instantiate the PGP class with specified encryption keys. This is useful when you have your public and private keys readily available. ```csharp public PGP(IEncryptionKeys encryptionKeys) ``` ```csharp EncryptionKeys keys = new EncryptionKeys(publicKeyFile, privateKeyFile, "password"); PGP pgp = new PGP(keys); ``` -------------------------------- ### Initialize EncryptionKeys with Private Key String Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Use this constructor to initialize EncryptionKeys with a private key provided as a string. This is suitable for signing and decryption operations when the key is not stored in a file. ```csharp public EncryptionKeys( string privateKey, string passPhrase) ``` ```csharp var keys = new EncryptionKeys(privateKeyStr, "password"); ``` -------------------------------- ### SigningSecretKey Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Gets the secret key used for signing operations. This corresponds to the private key used for signing. ```APIDOC ## SigningSecretKey ### Description Gets the secret key used for signing operations. ### Returns `PgpSecretKey` - The secret key, or null if no secret key is loaded. ``` -------------------------------- ### Initialize EncryptionKeys with Multiple Public Key Streams Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Use this constructor to initialize with multiple public keys from streams. It is intended for encryption and verification purposes. ```csharp public EncryptionKeys(IEnumerable publicKeyStreams) ``` -------------------------------- ### EncryptionKeys(FileInfo publicKeyFile, FileInfo privateKeyFile, string passPhrase) Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initializes a new instance of EncryptionKeys with public and private keys loaded from files, and a passphrase for decryption. ```APIDOC ## EncryptionKeys(FileInfo publicKeyFile, FileInfo privateKeyFile, string passPhrase) ### Description Initializes a new instance with public and private keys loaded from files. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **publicKeyFile** (FileInfo) - Required - Path to public key file - **privateKeyFile** (FileInfo) - Required - Path to private key file - **passPhrase** (string) - Required - Passphrase to decrypt the private key ### Request Example ```csharp var keys = new EncryptionKeys( new FileInfo("public.asc"), new FileInfo("private.asc"), "password"); ``` ### Response None explicitly documented for constructor. ### Throws `ArgumentException`, `FileNotFoundException`, `PgpException` ``` -------------------------------- ### Initialize EncryptionKeys with Multiple Public Keys and String Passphrase Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Use this constructor when you need to manage multiple public keys along with a single private key, and the passphrase is provided as a string. This is useful for scenarios involving multiple trusted parties. ```csharp public EncryptionKeys( IEnumerable publicKeys, string privateKey, string passPhrase) ``` ```csharp var publicKeysStr = new[] { pubKey1, pubKey2 }; var keys = new EncryptionKeys(publicKeysStr, privateKeyStr, "password"); ``` -------------------------------- ### Get Singleton PGP Instance Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Access the singleton instance of the PGP class. This instance is lazily initialized on its first access. ```csharp public static PGP Instance { get; } ``` ```csharp PGP pgp = PGP.Instance; ``` -------------------------------- ### EncryptionKeys(FileInfo publicKeyFile, FileInfo privateKeyFile, byte[] rawPassPhrase) Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initializes a new instance of EncryptionKeys with public and private keys loaded from files, using raw passphrase bytes. ```APIDOC ## EncryptionKeys(FileInfo publicKeyFile, FileInfo privateKeyFile, byte[] rawPassPhrase) ### Description Initializes a new instance with public and private keys loaded from files using raw passphrase bytes. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **publicKeyFile** (FileInfo) - Required - Path to public key file - **privateKeyFile** (FileInfo) - Required - Path to private key file - **rawPassPhrase** (byte[]) - Required - Raw passphrase bytes to decrypt the private key ### Request Example None provided. ### Response None explicitly documented for constructor. ### Throws `ArgumentException`, `FileNotFoundException`, `PgpException` ``` -------------------------------- ### Initialize EncryptionKeys with String Keys and Raw Byte Passphrase Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Use this constructor when your public and private keys are PGP-encoded strings, and you need to provide the passphrase as raw byte data. This is useful for handling sensitive passphrase data securely. ```csharp public EncryptionKeys( string publicKey, string privateKey, byte[] rawPassPhrase) ``` -------------------------------- ### PgpPublicKeyRingWithPreferredKey.PreferredEncryptionKey Property Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/models.md Gets the public key explicitly set as the preferred key for encryption. Returns null if no preference has been configured. ```csharp public PgpPublicKey PreferredEncryptionKey { get; } ``` -------------------------------- ### PgpPublicKeyRingWithPreferredKey.PgpPublicKeyRing Property Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/models.md Gets or sets the underlying BouncyCastle PgpPublicKeyRing. This property provides access to all public keys within the ring. ```csharp public PgpPublicKeyRing PgpPublicKeyRing { get; set; } ``` -------------------------------- ### Initialize EncryptionKeys with Public and Private Key Streams Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Use this constructor when public and private keys are available as streams. This is useful for in-memory operations or when reading keys from non-file sources. ```csharp public EncryptionKeys( Stream publicKeyStream, Stream privateKeyStream, string passPhrase) ``` ```csharp using (var pubStream = File.OpenRead("public.asc")) using (var privStream = File.OpenRead("private.asc")) { var keys = new EncryptionKeys(pubStream, privStream, "password"); } ``` -------------------------------- ### Get Recipients from Stream Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Retrieves recipient key IDs from a PGP encrypted stream. Ensure the stream is properly opened for reading. ```csharp public IEnumerable GetRecipients(Stream inputStream) ``` ```csharp using (var stream = File.OpenRead("message.pgp")) { var keyIds = pgp.GetRecipients(stream); } ``` -------------------------------- ### EncryptionKeys(string privateKey, string passPhrase) Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initializes a new instance with only a private key loaded from a string (for signing/decryption only). ```APIDOC ## EncryptionKeys(string privateKey, string passPhrase) ### Description Initializes a new instance with only a private key loaded from a string (for signing/decryption only). ### Parameters #### Path Parameters - **privateKey** (string) - Required - PGP-encoded private key string - **passPhrase** (string) - Required - Passphrase to decrypt the private key ### Request Example ```csharp var keys = new EncryptionKeys(privateKeyStr, "password"); ``` ### Throws: `ArgumentException`, `ArgumentNullException`, `PgpException` ``` -------------------------------- ### MasterKey Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Gets the master public key from the first loaded public key ring. This is often the primary key in a key ring. ```APIDOC ## MasterKey ### Description Gets the master public key from the first loaded public key ring. ### Returns `PgpPublicKey` ### Example ```csharp var masterId = encryptionKeys.MasterKey.KeyId; ``` ``` -------------------------------- ### EncryptionKeys(IEnumerable publicKeyStreams, Stream privateKeyStream, string passPhrase) Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initializes a new instance with multiple public key streams and a single private key stream. ```APIDOC ## EncryptionKeys(IEnumerable publicKeyStreams, Stream privateKeyStream, string passPhrase) ### Description Initializes a new instance with multiple public key streams and a single private key stream. ### Parameters #### Path Parameters - **publicKeyStreams** (IEnumerable) - Required - Collection of streams containing public key data - **privateKeyStream** (Stream) - Required - Stream containing private key data - **passPhrase** (string) - Required - Passphrase to decrypt the private key ### Throws: `ArgumentException`, `ArgumentNullException`, `PgpException` ``` -------------------------------- ### EncryptKeys Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Gets the collection of public keys that are suitable for encryption operations. This allows direct access to keys intended for encrypting data. ```APIDOC ## EncryptKeys ### Description Gets the collection of public keys suitable for encryption. ### Returns `IEnumerable` ### Example ```csharp foreach (var key in encryptionKeys.EncryptKeys) { Console.WriteLine($"Key ID: {key.KeyId:X}"); } ``` ``` -------------------------------- ### EncryptionKeys(Stream publicKeyStream, Stream privateKeyStream, string passPhrase) Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initializes a new instance with public and private keys loaded from streams. ```APIDOC ## EncryptionKeys(Stream publicKeyStream, Stream privateKeyStream, string passPhrase) ### Description Initializes a new instance with public and private keys loaded from streams. ### Parameters #### Path Parameters - **publicKeyStream** (Stream) - Required - Stream containing public key data - **privateKeyStream** (Stream) - Required - Stream containing private key data - **passPhrase** (string) - Required - Passphrase to decrypt the private key ### Request Example ```csharp using (var pubStream = File.OpenRead("public.asc")) using (var privStream = File.OpenRead("private.asc")) { var keys = new EncryptionKeys(pubStream, privStream, "password"); } ``` ### Throws: `ArgumentException`, `ArgumentNullException`, `PgpException` ``` -------------------------------- ### EncryptionKeys(Stream privateKeyStream, string passPhrase) Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initializes a new instance with only a private key stream (for signing/decryption only). ```APIDOC ## EncryptionKeys(Stream privateKeyStream, string passPhrase) ### Description Initializes a new instance with only a private key stream (for signing/decryption only). ### Parameters #### Path Parameters - **privateKeyStream** (Stream) - Required - Stream containing private key data - **passPhrase** (string) - Required - Passphrase to decrypt the private key ### Throws: `ArgumentException`, `ArgumentNullException`, `PgpException` ``` -------------------------------- ### Get PGP Message Symmetric Key Algorithm Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/models.md Retrieves the symmetric encryption algorithm used for the PGP message, such as AES256 or TripleDes. ```csharp Console.WriteLine($"Encrypted with: {result.SymmetricKeyAlgorithm}"); ``` -------------------------------- ### Get Recipients from FileInfo Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Retrieves recipient key IDs from a PGP encrypted file. Requires the FileInfo object representing the encrypted file. ```csharp public IEnumerable GetRecipients(FileInfo inputFileInfo) ``` ```csharp IEnumerable keyIds = pgp.GetRecipients(new FileInfo("message.pgp")); foreach (var keyId in keyIds) { Console.WriteLine($"Recipient Key ID: {keyId:X}"); } ``` -------------------------------- ### Clear Signing a File Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/README.md Creates a clear-signed file, where the original text remains readable, and signs it with a private key. The signature can then be verified and the original text read. ```csharp // Load private key var keys = new EncryptionKeys(privateKeyFile, "password"); var pgp = new PGP(keys); // Create clear-signed file (original text is readable) await pgp.ClearSignAsync(inputFile, outputFile) // Verify and read var result = await pgp.VerifyAndReadClearAsync(outputFile); if (result.IsVerified) { Console.WriteLine("Original: " + result.ClearText); } ``` -------------------------------- ### Initialize EncryptionKeys with Public Key Stream Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initialize an instance with a public key directly from a stream. This constructor is for encryption and verification. ```csharp public EncryptionKeys(Stream publicKeyStream) ``` -------------------------------- ### SymmetricKey Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Gets or sets an optional symmetric key used for symmetric encryption/decryption. This allows for hybrid encryption scenarios or pure symmetric encryption. ```APIDOC ## SymmetricKey ### Description Gets or sets an optional symmetric key used for symmetric encryption/decryption alongside or instead of asymmetric PGP encryption. ### Example ```csharp // Enable symmetric encryption encryptionKeys.SymmetricKey = new byte[] { 0x00, 0x01, /* ... */ }; ``` ``` -------------------------------- ### Initialize EncryptionKeys with Private Key Stream Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Use this constructor to initialize EncryptionKeys with a private key provided as a stream. This is suitable for signing and decryption operations when the key is not stored in a file. ```csharp public EncryptionKeys( Stream privateKeyStream, string passPhrase) ``` -------------------------------- ### Access Signing Private Key Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Gets the private key designated for signing operations. This property returns null if no private key is loaded. ```csharp public PgpPrivateKey SigningPrivateKey { get; } ``` ```csharp if (encryptionKeys.SigningPrivateKey != null) { // Can sign } ``` -------------------------------- ### Handle Missing Key Files Error Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/errors.md FileNotFoundException is thrown if key file paths do not exist during EncryptionKeys instantiation. Ensure file paths are correct and readable. ```csharp // Will throw FileNotFoundException if files don't exist var keys = new EncryptionKeys(publicKeyFile, privateKeyFile, password); ``` -------------------------------- ### Get PGP Message Modification Timestamp Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/models.md Retrieves the modification timestamp from the literal data packet, indicating when the original file was created or modified. ```csharp Console.WriteLine($"File timestamp: {result.ModificationDateTime:u}"); ``` -------------------------------- ### SecretKeys Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Gets the complete secret key ring bundle containing all loaded private keys. This provides access to all secret keys managed by the class. ```APIDOC ## SecretKeys ### Description Gets the complete secret key ring bundle containing all loaded private keys. ### Returns `PgpSecretKeyRingBundle` - The complete secret key ring bundle, or null if no private keys are loaded. ``` -------------------------------- ### Sign File with PGP Core Source: https://github.com/mattosaurus/pgpcore/blob/master/README.md Signs a file using a private key and password. Ensure the private key, password, and input file are correct. ```C# // Load keys FileInfo privateKey = new FileInfo(@"C:\TEMP\Keys\private.asc"); EncryptionKeys encryptionKeys = new EncryptionKeys(privateKey, "password"); // Reference input/output files FileInfo inputFile = new FileInfo(@"C:\TEMP\Content\content.txt"); FileInfo signedFile = new FileInfo(@"C:\TEMP\Content\signed.pgp"); // Sign PGP pgp = new PGP(encryptionKeys); await pgp.SignAsync(inputFile, signedFile); ``` -------------------------------- ### VerificationKeys Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Gets the collection of public keys that are suitable for signature verification. This property provides access to keys needed to confirm the authenticity of signed data. ```APIDOC ## VerificationKeys ### Description Gets the collection of public keys suitable for signature verification. ### Returns `IEnumerable` ### Example ```csharp foreach (var key in encryptionKeys.VerificationKeys) { // Use for verification } ``` ``` -------------------------------- ### PgpInspectResult Constructor with Full Parameters Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/models.md Initializes a new instance of PgpInspectResult with all possible parameters. ```csharp public PgpInspectResult( bool isArmored, bool isCompressed, bool isEncrypted, bool isIntegrityProtected, bool isSigned, SymmetricKeyAlgorithmTag symmetricKeyAlgorithm, Dictionary messageHeaders, string fileName, DateTime modificationDateTime) ``` -------------------------------- ### Access Master Public Key Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Gets the master public key from the first loaded public key ring. This is often the primary key for a user. ```csharp public PgpPublicKey MasterKey { get; } ``` ```csharp var masterId = encryptionKeys.MasterKey.KeyId; ``` -------------------------------- ### PgpPublicKeyRingWithPreferredKey.DefaultEncryptionKey Property Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/models.md Gets the best available encryption key from the ring. It returns the preferred key if set, otherwise it automatically selects the most suitable key. ```csharp public PgpPublicKey DefaultEncryptionKey { get; } ``` -------------------------------- ### Catching FileNotFoundException for Key Files Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/errors.md Demonstrates how to catch a FileNotFoundException when initializing EncryptionKeys, specifically checking the FileName property for the missing file. ```csharp try { var keys = new EncryptionKeys(publicKeyFile, privateKeyFile, "password"); } catch (FileNotFoundException ex) { Console.WriteLine($"File missing: {ex.FileName}"); } ``` -------------------------------- ### Encrypt and Sign File Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/README.md Encrypts a file and signs it using both public and private keys. Requires loading both public and private keys with the private key's password. ```csharp // Load both keys var keys = new EncryptionKeys(publicKeyFile, privateKeyFile, "password"); var pgp = new PGP(keys); // Encrypt and sign await pgp.EncryptAndSignAsync(inputFile, outputFile); ``` -------------------------------- ### Get Recipients from ASCII-armored String Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/pgp.md Retrieves recipient key IDs from an ASCII-armored PGP encrypted message string. The input must be a valid ASCII-armored string. ```csharp public IEnumerable GetRecipients(string input) ``` ```csharp string message = "-----BEGIN PGP MESSAGE-----\n..."; var keyIds = pgp.GetRecipients(message); ``` -------------------------------- ### EncryptionKeys(string publicKey) Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initializes a new instance with only a public key from a string, suitable for encryption and verification operations. The public key must be in PGP-encoded string format. ```APIDOC ## EncryptionKeys(string publicKey) ### Description Initializes a new instance with only a public key from a string (for encryption/verification only). ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **publicKey** (string) - Required - PGP-encoded public key string ### Request Example ```csharp var keys = new EncryptionKeys(publicKeyStr); ``` ### Response #### Success Response (200) - None explicitly documented. #### Response Example - None explicitly documented. ``` -------------------------------- ### Safe Symmetric Key Initialization with Argument Check Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/errors.md Ensures a symmetric key is not null or empty before initializing EncryptionKeys, throwing an ArgumentException if the key is invalid. Also catches PgpException for initialization failures. ```csharp try { byte[] symmetricKey = new byte[] { /* ... */ }; if (symmetricKey == null || symmetricKey.Length == 0) { throw new ArgumentException("Symmetric key cannot be null or empty"); } var keys = new EncryptionKeys(symmetricKey); } catch (ArgumentException ex) { Console.WriteLine($"Invalid symmetric key: {ex.Message}"); } catch (PgpException ex) { Console.WriteLine($"Failed to initialize symmetric encryption: {ex.Message}"); } ``` -------------------------------- ### PublicKeyRings Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Gets the collection of public key rings, each containing a preferred encryption key. This property is useful for iterating through available public keys for encryption purposes. ```APIDOC ## PublicKeyRings ### Description Gets the collection of public key rings with preferred encryption keys. ### Returns `IEnumerable` - Public key ring wrappers. ### Example ```csharp foreach (var keyRing in encryptionKeys.PublicKeyRings) { var key = keyRing.DefaultEncryptionKey; } ``` ``` -------------------------------- ### Get PGP Message Original Filename Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/models.md Retrieves the filename stored within the literal data packet of the PGP message. This value may be null if not present. ```csharp if (!string.IsNullOrEmpty(result.FileName)) { Console.WriteLine($"Original filename: {result.FileName}"); } ``` -------------------------------- ### Modern Encryption Settings Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/configuration.md Configure PGPCore with modern security algorithms for encryption. Use `armor: false` for improved performance when the output does not need to be ASCII armored. ```csharp var pgp = new PGP(keys); // Modern settings pgp.SymmetricKeyAlgorithm = SymmetricKeyAlgorithmTag.Aes256; pgp.HashAlgorithmTag = HashAlgorithmTag.Sha256; pgp.CompressionAlgorithm = CompressionAlgorithmTag.Zip; pgp.FileType = PGPFileType.UTF8; // Encrypt without armor for performance await pgp.EncryptAsync(inputFile, outputFile, armor: false, withIntegrityCheck: true); ``` -------------------------------- ### Access Public Keys for Encryption Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Gets the collection of public keys specifically designated for encryption operations. Iterate through this collection to select appropriate keys for encrypting data. ```csharp public IEnumerable EncryptKeys { get; } ``` ```csharp foreach (var key in encryptionKeys.EncryptKeys) { Console.WriteLine($"Key ID: {key.KeyId:X}"); } ``` -------------------------------- ### EncryptionKeys(Stream publicKeyStream) Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initializes a new instance with a single public key provided as a stream. This is used for encryption and verification operations when the public key is available as a stream. ```APIDOC ## EncryptionKeys(Stream publicKeyStream) ### Description Initializes a new instance with only a public key stream (for encryption/verification only). ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **publicKeyStream** (Stream) - Required - Stream containing public key data ### Request Example - None explicitly documented. ### Response #### Success Response (200) - None explicitly documented. #### Response Example - None explicitly documented. ``` -------------------------------- ### EncryptionKeys(IEnumerable publicKeyStreams) Source: https://github.com/mattosaurus/pgpcore/blob/master/_autodocs/api-reference/encryption-keys.md Initializes a new instance with multiple public keys provided as a collection of streams. This constructor is for encryption and verification using multiple public keys from streams. ```APIDOC ## EncryptionKeys(IEnumerable publicKeyStreams) ### Description Initializes a new instance with multiple public key streams (for encryption/verification only). ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - **publicKeyStreams** (IEnumerable) - Required - Collection of streams containing public key data ### Request Example - None explicitly documented. ### Response #### Success Response (200) - None explicitly documented. #### Response Example - None explicitly documented. ```