{
    "mode": "man",
    "parameter": "GnuPG",
    "section": "3",
    "url": "https://www.chedong.com/phpMan.php/man/GnuPG/3/json",
    "generated": "2026-09-03T17:45:04Z",
    "synopsis": "use GnuPG qw( :algo );\nmy $gpg = new GnuPG();\n$gpg->encrypt(  plaintext    => \"file.txt\",    output        => \"file.gpg\",\narmor    => 1,         sign    => 1,\npassphrase  => $secret );\n$gpg->decrypt( ciphertext    => \"file.gpg\",    output        => \"file.txt\" );\n$gpg->clearsign( plaintext => \"file.txt\", output => \"file.txt.asc\",\npassphrase => $secret,   armor => 1,\n);\n$gpg->verify( signature => \"file.txt.asc\", file => \"file.txt\" );\n$gpg->genkey( name => \"Joe Blow\",        comment => \"My GnuPG key\",\npassphrase => $secret,\n);",
    "sections": {
        "NAME": {
            "content": "GnuPG - Perl module interface to the GNU Privacy Guard (v1.x.x series)\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use GnuPG qw( :algo );\n\nmy $gpg = new GnuPG();\n\n$gpg->encrypt(  plaintext    => \"file.txt\",    output        => \"file.gpg\",\narmor    => 1,         sign    => 1,\npassphrase  => $secret );\n\n$gpg->decrypt( ciphertext    => \"file.gpg\",    output        => \"file.txt\" );\n\n$gpg->clearsign( plaintext => \"file.txt\", output => \"file.txt.asc\",\npassphrase => $secret,   armor => 1,\n);\n\n$gpg->verify( signature => \"file.txt.asc\", file => \"file.txt\" );\n\n$gpg->genkey( name => \"Joe Blow\",        comment => \"My GnuPG key\",\npassphrase => $secret,\n);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "GnuPG is a perl interface to the GNU Privacy Guard. It uses the shared memory coprocess\ninterface that gpg provides for its wrappers. It tries its best to map the interactive\ninterface of the gpg to a more programmatic model.\n",
            "subsections": []
        },
        "API OVERVIEW": {
            "content": "The API is accessed through methods on a GnuPG object which is a wrapper around the gpg\nprogram.  All methods take their argument using named parameters, and errors are returned by\nthrowing an exception (using croak).  If you want to catch errors you will have to use eval.\n\nWhen handed in a file handle for input or output parameters on many of the functions, the API\nattempts to tie that handle to STDIN and STDOUT. In certain persistent environments\n(particularly a web environment), this will not work. This problem can be avoided by passing\nin file names to all relevant parameters rather than a Perl file handle.\n\nThere is also a tied file handle interface which you may find more convenient for encryption\nand decryption. See GnuPG::Tie(3) for details.\n",
            "subsections": []
        },
        "CONSTRUCTOR": {
            "content": "",
            "subsections": [
                {
                    "name": "new ( [params] )",
                    "content": "You create a new GnuPG wrapper object by invoking its new method.  (How original !).  The\nmodule will try to finds the gpg program in your path and will croak if it can't find it.\nHere are the parameters that it accepts :\n\ngnupgpath\nPath to the gpg program.\n\noptions\nPath  to the options file for gpg. If not specified, it will use the default one (usually\n~/.gnupg/options).\n\nhomedir\nPath to the gpg home directory. This is the directory that contains the  default  options\nfile, the public and private key rings as well as the trust database.\n\ntrace\nIf this variable is set to true, gpg debugging output will be sent to stderr.\n\nExample: my $gpg = new GnuPG();\n"
                }
            ]
        },
        "METHODS": {
            "content": "",
            "subsections": [
                {
                    "name": "gen_key( [params] )",
                    "content": "This  methods  is used to create a new gpg key pair. The methods croaks if there is an error.\nIt is a good idea to press random keys on the keyboard while running this methods because  it\nconsumes a lot of entropy from the computer. Here are the parameters it accepts :\n\nalgo\nThis is the algorithm use to create the key. Can be DSAELGAMAL, DSA, RSARSA or RSA.  It\ndefaults to DSAELGAMAL. To import those constant in your name space, use the :algo tag.\n\nsize\nThe  size  of  the  public  key. Defaults to 1024. Cannot be less than 768 bits, and keys\nlonger than 2048 are also discouraged. (You *DO* know that your monitor  may  be  leaking\nsensitive information ;-).\n\nvalid\nHow long the key is valid. Defaults to 0 or never expire.\n\nname\nThis  is  the  only  mandatory argument. This is the name that will used to construct the\nuser id.\n\nemail\nOptional email portion of the user id.\n\ncomment\nOptional comment portion of the user id.\n\npassphrase\nThe passphrase that will be used to  encrypt  the  private  key.  Optional  but  strongly\nrecommended.\n\nExample: $gpg->genkey( algo => DSAELGAMAL, size => 1024,\nname => \"My name\" );\n"
                },
                {
                    "name": "import_keys( [params] )",
                    "content": "Import  keys  into the GnuPG private or public keyring. The method croaks if it encounters an\nerror. It returns the number of keys imported. Parameters :\n\nkeys\nOnly parameter and mandatory. It can either be a filename or  a  reference  to  an  array\ncontaining a list of files that will be imported.\n\nExample: $gpg->importkeys( keys => [ qw( key.pub key.sec ) ] );\n"
                },
                {
                    "name": "export_keys( [params] )",
                    "content": "Exports keys from the GnuPG keyrings. The method croaks if it encounters an error. Parameters\n:\n\nkeys\nOptional argument that restricts the keys that will be exported.  Can either be a user id\nor  a  reference  to  an  array of userid that specifies the keys to be exported. If left\nunspecified, all keys will be exported.\n\nsecret\nIf this argument is to true, the  secret  keys  rather  than  the  public  ones  will  be\nexported.\n\nall If this argument is set to true, all keys (even those that aren't OpenPGP compliant) will\nbe exported.\n\noutput\nThis  argument  specifies where the keys will be exported. Can be either a file name or a\nreference to a file handle. If not specified, the keys will be exported to stdout.\n\narmor\nSet this parameter to true, if you want the exported keys to be ASCII armored.\n\nExample: $gpg->exportkeys( armor => 1, output => \"keyring.pub\" );\n"
                },
                {
                    "name": "encrypt( [params] )",
                    "content": "This method is used to encrypt a message, either using assymetric or symmetric  cryptography.\nThe methods croaks if an error is encountered. Parameters:\n\nplaintext\nThis  argument specifies what to encrypt. It can be either a filename or a reference to a\nfile handle. If left unspecified, STDIN will be encrypted.\n\noutput\nThis optional argument specifies where the ciphertext will be output.  It can be either a\nfile name or a reference to a file handle. If left unspecified, the  ciphertext  will  be\nsent to STDOUT.\n\narmor\nIf this parameter is set to true, the ciphertext will be ASCII armored.\n\nsymmetric\nIf  this  parameter  is  set  to true, symmetric cryptography will be used to encrypt the\nmessage. You will need to provide a passphrase parameter.\n\nrecipient\nIf not using symmetric cryptography, you will have to provide this parameter.  It  should\ncontains  the userid of the intended recipient of the message. It will be used to look up\nthe key to use to encrypt the message. The parameter can also take an array ref,  if  you\nwant to encrypt the message for a group of recipients.\n\nsign\nIf this parameter is set to true, the message will also be signed. You will probably have\nto  use  the  passphrase  parameter  to unlock the private key used to sign message. This\noption is incompatible with the symmetric one.\n\nlocal-user\nThis parameter is used to specified the private  key  that  will  be  used  to  sign  the\nmessage. If left unspecified, the default user will be used. This option only makes sense\nwhen using the sign option.\n\npassphrase\nThis  parameter  contains either the secret passphrase for the symmetric algorithm or the\npassphrase that should be used to decrypt the private key.\n\nExample: $gpg->encrypt( plaintext => file.txt, output => \"file.gpg\",\nsign => 1, passphrase => $secret\n);\n"
                },
                {
                    "name": "sign( [params] )",
                    "content": "This method is used create a signature for a file or stream of data.  This method  croaks  on\nerrors. Parameters :\n\nplaintext\nThis  argument  specifies  what  to sign. It can be either a filename or a reference to a\nfile handle. If left unspecified, the data read on STDIN will be signed.\n\noutput\nThis optional argument specifies where the signature will be output.  It can be either  a\nfile  name  or  a  reference to a file handle. If left unspecified, the signature will be\nsent to STDOUT.\n\narmor\nIf this parameter is set to true, the signature will be ASCII armored.\n\npassphrase\nThis parameter contains the secret that should be used to decrypt the private key.\n\nlocal-user\nThis parameter is used to specified the private  key  that  will  be  used  to  make  the\nsignature . If left unspecified, the default user will be used.\n\ndetach-sign\nIf set to true, a digest of the data will be signed rather than the whole file.\n\nExample: $gpg->sign( plaintext => \"file.txt\", output => \"file.txt.asc\",\narmor => 1,\n);\n"
                },
                {
                    "name": "clearsign( [params] )",
                    "content": "This  methods  clearsign  a  message.  The  output  will contains the original message with a\nsignature appended. It takes the same parameters as the sign method.\n"
                },
                {
                    "name": "verify( [params] )",
                    "content": "This method verifies a signature against the  signed  message.  The  methods  croaks  if  the\nsignature  is  invalid  or  an error is encountered. If the signature is valid, it returns an\nhash with the signature parameters. Here are the method's parameters :\n\nsignature\nIf the message and the signature are in the same file (i.e. a clearsigned message),  this\nparameter  can  be  either  a file name or a reference to a file handle. If the signature\ndoesn't follows the message, than it must be the name  of  the  file  that  contains  the\nsignature.\n\nfile\nThis  is  a  file  name or a reference to an array of file names that contains the signed\ndata.\n\nWhen the signature is valid, here are the elements of the hash that is returned by the method\n:\n\nsigid\nThe signature id. This can be used to protect against replay attack.\n\ndate\nThe data at which the signature has been made.\n\ntimestamp\nThe epoch timestamp of the signature.\n\nkeyid\nThe key id used to make the signature.\n\nuser\nThe userid of the signer.\n\nfingerprint\nThe fingerprint of the signature.\n\ntrust\nThe trust value of the public key of the signer. Those are values that can be imported in\nyour  namespace  with  the  :trust   tag.   They   are   (TRUSTUNDEFINED,   TRUSTNEVER,\nTRUSTMARGINAL, TRUSTFULLY, TRUSTULTIMATE).\n\nExample : my $sig = $gpg->verify( signature => \"file.txt.asc\",\nfile => \"file.txt\" );\n"
                },
                {
                    "name": "decrypt( [params] )",
                    "content": "This  method  decrypts an encrypted message. It croaks, if there is an error while decrypting\nthe message. If the  message  was  signed,  this  method  also  verifies  the  signature.  If\ndecryption is sucessful, the method either returns the valid signature parameters if present,\nor true. Method parameters :\n\nciphertext\nThis optional parameter contains either the name of the file containing the ciphertext or\na  reference  to  a  file handle containing the ciphertext. If not present, STDIN will be\ndecrypted.\n\noutput\nThis optional parameter determines where the plaintext will be stored.  It can be  either\na  file name or a reference to a file handle.  If left unspecified, the plaintext will be\nsent to STDOUT.\n\nsymmetric\nThis should be set to true, if the message is encrypted using symmetric cryptography.\n\npassphrase\nThe passphrase that should be used to decrypt the message  (in  the  case  of  a  message\nencrypted  using  a symmetric cipher) or the secret that will unlock the private key that\nshould be used to decrypt the message.\n\nExample: $gpg->decrypt( ciphertext => \"file.gpg\", output => \"file.txt\"\npassphrase => $secret );\n"
                }
            ]
        },
        "BUGS AND LIMITATIONS": {
            "content": "This module doesn't work (yet) with the v2 branch of GnuPG.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Francis J. Lacoste <francis.lacoste@Contre.COM>\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright (c) 1999,2000 iNsu Innovations. Inc.  Copyright (c) 2001 Francis J. Lacoste\n\nThis program is free software; you can redistribute it and/or modify it under  the  terms  of\nthe GNU General Public License as published by the Free Software Foundation; either version 2\nof the License, or (at your option) any later version.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "GnuPG::Tie\n\nAlternative module: GnuPG::Interface\n\ngpg(1)\n\nperl v5.36.0                                 2022-10-13                                   GnuPG(3pm)",
            "subsections": []
        }
    },
    "summary": "GnuPG - Perl module interface to the GNU Privacy Guard (v1.x.x series)",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "gpg",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/gpg/1/json"
        }
    ]
}