(PECL gnupg >= 0.4)

gnupg_initInitialize a connection


gnupg_init(?array $options = null): resource

Bağımsız Değişkenler


Must be an associative array. It is used to change the default configuration of the crypto engine.

Configuration overrides
key type description
file_name string It is the file name of the executable program implementing this protocol which is usually path of the gpg executable.
home_dir string It is the directory name of the configuration directory. It also overrides GNUPGHOME environment variable that is used for the same purpose.

Dönen Değerler

A GnuPG resource connection used by other GnuPG functions.

Sürüm Bilgisi

Sürüm: Açıklama
1.5.0 The options parameter was added.


Örnek 1 Procedural gnupg_init() example with default setting

= gnupg_init();

Örnek 2 Procedural gnupg_init() example with overriden file name and home dir

= gnupg_init(["file_name" => "/usr/bin/gpg2", "home_dir" => "/var/www/.gnupg"]);

Örnek 3 OO gnupg initializer example with default setting

= new gnupg();

Örnek 4 OO gnupg initializer example with overriden file name and home dir

= new gnupg(["file_name" => "/usr/bin/gpg2", "home_dir" => "/var/www/.gnupg"]);

add a note

User Contributed Notes 2 notes

der_axel at gmx dot de
6 years ago
Set the correct GNUPG environment, before you call gnupg_init()!

The current FPM/FastCGI/Module User must have read - if you import write - permissions on that directory. You won't get an error message, if something is not correct.
Without a correct environment, all other gnupg functions will not work as you expected.

// Enter your .gnupg environment
$res = gnupg_init();
$info = gnupg_keyinfo($res, 'your-key-id');
"Key - Info<pre>";
2 years ago
Make sure home_dir option is not too many characters or else private keys fail.

You will notice that functions take a long time (seconds).

Commandline test yield error:
> gpg: can't connect to the agent: IPC connect call failed

Executing `gpg-agent --daemon --homedir /very/long/path/to/.gnupg` gave the error.
> socket name for '/very/long/path/to/.gnupg/S.gpg-agent.extra' is too long

So you must check that home_dir + '/S.gpg-agent.extra' is:
* < 107 characters on Linux
* < 104 on BSD 4.4
To Top