API Reference

This page provides the complete API documentation for the RobotFrameworkPGP library.

RobotFrameworkPGP Class

class RobotFrameworkPGP.pgp_library.RobotFrameworkPGP(gnupg_home=None)[source]

Bases: object

Robot Framework library for PGP/GPG encryption and decryption operations.

This library provides keywords for: - Text and file encryption/decryption - Key generation and management - Digital signatures - GPG operations

= Table of contents =

  • Initialization

  • Configuration

  • Encryption and Decryption

  • Key Management

  • Digital Signatures

  • Utility Keywords

= Initialization =

The library can be imported with optional parameters:

Library | RobotFrameworkPGP |
Library | RobotFrameworkPGP | gnupg_home=/path/to/gnupg |

= Configuration =

Before using encryption/decryption operations, you need to configure the GPG environment.

= Examples =

Set GPG Home Directory | /tmp/gnupg |
Generate Key Pair | test@example.com | Test User | 2048 |
${encrypted} | Encrypt Text | Hello World | test@example.com |
${decrypted} | Decrypt Text | ${encrypted} | passphrase=secret |
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
ROBOT_LIBRARY_VERSION = '1.1.1'
ROBOT_LIBRARY_DOC_FORMAT = 'ROBOT'
__init__(gnupg_home=None)[source]

Initialize the PGP library.

Parameters:

gnupg_home (Optional[str]) – Optional path to GPG home directory. If not provided, a temporary directory will be created.

set_gpg_home_directory(gnupg_home)[source]

Set the GPG home directory.

Parameters:

gnupg_home (str) – Path to the GPG home directory.

Return type:

None

Example

Set GPG Home Directory | /tmp/my_gnupg |
generate_key_pair(email, name, key_length=2048, passphrase=None, expire_date='0')[source]

Generate a new GPG key pair.

Parameters:
  • email (str) – Email address for the key

  • name (str) – Name for the key

  • key_length (int) – Key length in bits (default: 2048)

  • passphrase (Optional[str]) – Passphrase to protect the private key

  • expire_date (str) – Expiration date (0 for no expiration)

Return type:

str

Returns:

Key fingerprint of the generated key

Example

${fingerprint} | Generate Key Pair | test@example.com | Test User | 2048 | secret123 |
import_key(key_data)[source]

Import a GPG key from key data.

Parameters:

key_data (str) – The key data to import (ASCII armored)

Return type:

List[str]

Returns:

List of imported key fingerprints

Example

${fingerprints} | Import Key | ${key_data} |
import_key_from_file(key_file_path)[source]

Import a GPG key from a file.

Parameters:

key_file_path (str) – Path to the key file

Return type:

List[str]

Returns:

List of imported key fingerprints

Example

${fingerprints} | Import Key From File | /path/to/public.key |
export_public_key(key_id)[source]

Export a public key.

Parameters:

key_id (str) – Key ID, fingerprint, or email address

Return type:

str

Returns:

ASCII armored public key

Example

${public_key} | Export Public Key | test@example.com |
export_private_key(key_id, passphrase=None)[source]

Export a private key.

Parameters:
  • key_id (str) – Key ID, fingerprint, or email address

  • passphrase (Optional[str]) – Passphrase to unlock the private key

Return type:

str

Returns:

ASCII armored private key

Example

${private_key} | Export Private Key | test@example.com | secret123 |
list_keys(secret=False)[source]

List GPG keys.

Parameters:

secret (bool) – If True, list secret keys; otherwise list public keys

Return type:

List[Dict[str, Any]]

Returns:

List of key information dictionaries

Example

${keys} | List Keys |
${secret_keys} | List Keys | secret=${True} |
encrypt_text(text, recipients, sign=None, passphrase=None, armor=True)[source]

Encrypt text for specified recipients.

Parameters:
  • text (str) – Text to encrypt

  • recipients (Union[str, List[str]]) – Recipient key ID(s), fingerprint(s), or email address(es)

  • sign (Optional[str]) – Optional key ID to sign with

  • passphrase (Optional[str]) – Passphrase for signing key

  • armor (bool) – If True, return ASCII armored output

Return type:

str

Returns:

Encrypted text

Example

${encrypted} | Encrypt Text | Hello World | test@example.com |
${encrypted} | Encrypt Text | Secret message | test@example.com | sign=signer@example.com | passphrase=secret |
decrypt_text(encrypted_text, passphrase=None)[source]

Decrypt encrypted text.

Parameters:
  • encrypted_text (str) – Encrypted text to decrypt

  • passphrase (Optional[str]) – Passphrase to unlock the private key

Return type:

str

Returns:

Decrypted text

Example

${decrypted} | Decrypt Text | ${encrypted_text} | passphrase=secret |
encrypt_file(input_file, output_file, recipients, sign=None, passphrase=None, armor=True)[source]

Encrypt a file for specified recipients.

Parameters:
  • input_file (str) – Path to the input file

  • output_file (str) – Path to the output encrypted file

  • recipients (Union[str, List[str]]) – Recipient key ID(s), fingerprint(s), or email address(es)

  • sign (Optional[str]) – Optional key ID to sign with

  • passphrase (Optional[str]) – Passphrase for signing key

  • armor (bool) – If True, create ASCII armored output

Return type:

None

Example

Encrypt File | input.txt | output.txt.gpg | test@example.com |
decrypt_file(input_file, output_file, passphrase=None)[source]

Decrypt an encrypted file.

Parameters:
  • input_file (str) – Path to the encrypted input file

  • output_file (str) – Path to the decrypted output file

  • passphrase (Optional[str]) – Passphrase to unlock the private key

Return type:

None

Example

Decrypt File | input.txt.gpg | output.txt | passphrase=secret |
sign_text(text, key_id, passphrase=None)[source]

Create a digital signature for text.

Parameters:
  • text (str) – Text to sign

  • key_id (str) – Key ID, fingerprint, or email address to sign with

  • passphrase (Optional[str]) – Passphrase to unlock the private key

Return type:

str

Returns:

Signed text (cleartext signature)

Example

${signed} | Sign Text | Hello World | test@example.com | passphrase=secret |
verify_signature(signed_text)[source]

Verify a digital signature.

Parameters:

signed_text (str) – Signed text to verify

Return type:

Dict[str, Any]

Returns:

Dictionary with verification results

Example

${result} | Verify Signature | ${signed_text} |
Should Be True | ${result}[valid] |
delete_key(key_id, secret=False, passphrase=None)[source]

Delete a GPG key.

Parameters:
  • key_id (str) – Key ID, fingerprint, or email address

  • secret (bool) – If True, delete secret key; otherwise delete public key

  • passphrase (Optional[str]) – Passphrase to unlock the private key (for secret key deletion)

Return type:

None

Example

Delete Key | test@example.com |
Delete Key | test@example.com | secret=${True} | passphrase=secret |
get_gpg_version()[source]

Get the GPG version information.

Return type:

str

Returns:

GPG version string

Example

${version} | Get GPG Version |
get_key_info(key_id)[source]

Get detailed information about a specific key.

Parameters:

key_id (str) – Key ID, fingerprint, or email address

Return type:

Dict[str, Any]

Returns:

Dictionary with key information

Example

${info} | Get Key Info | test@example.com |
create_symmetric_encryption(text, passphrase)[source]

Create symmetric encryption (password-based).

Parameters:
  • text (str) – Text to encrypt

  • passphrase (str) – Passphrase for encryption

Return type:

str

Returns:

Encrypted text

Example

${encrypted} | Create Symmetric Encryption | Secret data | mypassword |
ROBOT_AUTO_KEYWORDS = False

Module Contents

Robot Framework library for PGP/GPG encryption and decryption operations.

class RobotFrameworkPGP.RobotFrameworkPGP(gnupg_home=None)[source]

Bases: object

Robot Framework library for PGP/GPG encryption and decryption operations.

This library provides keywords for: - Text and file encryption/decryption - Key generation and management - Digital signatures - GPG operations

= Table of contents =

  • Initialization

  • Configuration

  • Encryption and Decryption

  • Key Management

  • Digital Signatures

  • Utility Keywords

= Initialization =

The library can be imported with optional parameters:

Library | RobotFrameworkPGP |
Library | RobotFrameworkPGP | gnupg_home=/path/to/gnupg |

= Configuration =

Before using encryption/decryption operations, you need to configure the GPG environment.

= Examples =

Set GPG Home Directory | /tmp/gnupg |
Generate Key Pair | test@example.com | Test User | 2048 |
${encrypted} | Encrypt Text | Hello World | test@example.com |
${decrypted} | Decrypt Text | ${encrypted} | passphrase=secret |
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
ROBOT_LIBRARY_VERSION = '1.1.1'
ROBOT_LIBRARY_DOC_FORMAT = 'ROBOT'
__init__(gnupg_home=None)[source]

Initialize the PGP library.

Parameters:

gnupg_home (Optional[str]) – Optional path to GPG home directory. If not provided, a temporary directory will be created.

set_gpg_home_directory(gnupg_home)[source]

Set the GPG home directory.

Parameters:

gnupg_home (str) – Path to the GPG home directory.

Return type:

None

Example

Set GPG Home Directory | /tmp/my_gnupg |
generate_key_pair(email, name, key_length=2048, passphrase=None, expire_date='0')[source]

Generate a new GPG key pair.

Parameters:
  • email (str) – Email address for the key

  • name (str) – Name for the key

  • key_length (int) – Key length in bits (default: 2048)

  • passphrase (Optional[str]) – Passphrase to protect the private key

  • expire_date (str) – Expiration date (0 for no expiration)

Return type:

str

Returns:

Key fingerprint of the generated key

Example

${fingerprint} | Generate Key Pair | test@example.com | Test User | 2048 | secret123 |
import_key(key_data)[source]

Import a GPG key from key data.

Parameters:

key_data (str) – The key data to import (ASCII armored)

Return type:

List[str]

Returns:

List of imported key fingerprints

Example

${fingerprints} | Import Key | ${key_data} |
import_key_from_file(key_file_path)[source]

Import a GPG key from a file.

Parameters:

key_file_path (str) – Path to the key file

Return type:

List[str]

Returns:

List of imported key fingerprints

Example

${fingerprints} | Import Key From File | /path/to/public.key |
export_public_key(key_id)[source]

Export a public key.

Parameters:

key_id (str) – Key ID, fingerprint, or email address

Return type:

str

Returns:

ASCII armored public key

Example

${public_key} | Export Public Key | test@example.com |
export_private_key(key_id, passphrase=None)[source]

Export a private key.

Parameters:
  • key_id (str) – Key ID, fingerprint, or email address

  • passphrase (Optional[str]) – Passphrase to unlock the private key

Return type:

str

Returns:

ASCII armored private key

Example

${private_key} | Export Private Key | test@example.com | secret123 |
list_keys(secret=False)[source]

List GPG keys.

Parameters:

secret (bool) – If True, list secret keys; otherwise list public keys

Return type:

List[Dict[str, Any]]

Returns:

List of key information dictionaries

Example

${keys} | List Keys |
${secret_keys} | List Keys | secret=${True} |
encrypt_text(text, recipients, sign=None, passphrase=None, armor=True)[source]

Encrypt text for specified recipients.

Parameters:
  • text (str) – Text to encrypt

  • recipients (Union[str, List[str]]) – Recipient key ID(s), fingerprint(s), or email address(es)

  • sign (Optional[str]) – Optional key ID to sign with

  • passphrase (Optional[str]) – Passphrase for signing key

  • armor (bool) – If True, return ASCII armored output

Return type:

str

Returns:

Encrypted text

Example

${encrypted} | Encrypt Text | Hello World | test@example.com |
${encrypted} | Encrypt Text | Secret message | test@example.com | sign=signer@example.com | passphrase=secret |
decrypt_text(encrypted_text, passphrase=None)[source]

Decrypt encrypted text.

Parameters:
  • encrypted_text (str) – Encrypted text to decrypt

  • passphrase (Optional[str]) – Passphrase to unlock the private key

Return type:

str

Returns:

Decrypted text

Example

${decrypted} | Decrypt Text | ${encrypted_text} | passphrase=secret |
encrypt_file(input_file, output_file, recipients, sign=None, passphrase=None, armor=True)[source]

Encrypt a file for specified recipients.

Parameters:
  • input_file (str) – Path to the input file

  • output_file (str) – Path to the output encrypted file

  • recipients (Union[str, List[str]]) – Recipient key ID(s), fingerprint(s), or email address(es)

  • sign (Optional[str]) – Optional key ID to sign with

  • passphrase (Optional[str]) – Passphrase for signing key

  • armor (bool) – If True, create ASCII armored output

Return type:

None

Example

Encrypt File | input.txt | output.txt.gpg | test@example.com |
decrypt_file(input_file, output_file, passphrase=None)[source]

Decrypt an encrypted file.

Parameters:
  • input_file (str) – Path to the encrypted input file

  • output_file (str) – Path to the decrypted output file

  • passphrase (Optional[str]) – Passphrase to unlock the private key

Return type:

None

Example

Decrypt File | input.txt.gpg | output.txt | passphrase=secret |
sign_text(text, key_id, passphrase=None)[source]

Create a digital signature for text.

Parameters:
  • text (str) – Text to sign

  • key_id (str) – Key ID, fingerprint, or email address to sign with

  • passphrase (Optional[str]) – Passphrase to unlock the private key

Return type:

str

Returns:

Signed text (cleartext signature)

Example

${signed} | Sign Text | Hello World | test@example.com | passphrase=secret |
verify_signature(signed_text)[source]

Verify a digital signature.

Parameters:

signed_text (str) – Signed text to verify

Return type:

Dict[str, Any]

Returns:

Dictionary with verification results

Example

${result} | Verify Signature | ${signed_text} |
Should Be True | ${result}[valid] |
delete_key(key_id, secret=False, passphrase=None)[source]

Delete a GPG key.

Parameters:
  • key_id (str) – Key ID, fingerprint, or email address

  • secret (bool) – If True, delete secret key; otherwise delete public key

  • passphrase (Optional[str]) – Passphrase to unlock the private key (for secret key deletion)

Return type:

None

Example

Delete Key | test@example.com |
Delete Key | test@example.com | secret=${True} | passphrase=secret |
get_gpg_version()[source]

Get the GPG version information.

Return type:

str

Returns:

GPG version string

Example

${version} | Get GPG Version |
get_key_info(key_id)[source]

Get detailed information about a specific key.

Parameters:

key_id (str) – Key ID, fingerprint, or email address

Return type:

Dict[str, Any]

Returns:

Dictionary with key information

Example

${info} | Get Key Info | test@example.com |
create_symmetric_encryption(text, passphrase)[source]

Create symmetric encryption (password-based).

Parameters:
  • text (str) – Text to encrypt

  • passphrase (str) – Passphrase for encryption

Return type:

str

Returns:

Encrypted text

Example

${encrypted} | Create Symmetric Encryption | Secret data | mypassword |
ROBOT_AUTO_KEYWORDS = False