gnupg_init

(PECL gnupg >= 0.4)

gnupg_initInitialize a connection

Descrizione

gnupg_init(?array $options = null): resource

Elenco dei parametri

options

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.

Valori restituiti

A GnuPG resource connection used by other GnuPG functions.

Log delle modifiche

Versione Descrizione
1.5.0 The options parameter was added.

Esempi

Example #1 Procedural gnupg_init() example with default setting

<?php
$res
= gnupg_init();
?>

Example #2 Procedural gnupg_init() example with overriden file name and home dir

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

Example #3 OO gnupg initializer example with default setting

<?php
$gpg
= new gnupg();
?>

Example #4 OO gnupg initializer example with overriden file name and home dir

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

add a note add a note

User Contributed Notes 1 note

up
5
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.

<?php
// Enter your .gnupg environment
putenv('GNUPGHOME=/var/www/vhosts/yourdomain/.gnupg');
error_reporting(E_ALL);
$res = gnupg_init();
gnupg_seterrormode($res,GNUPG_ERROR_WARNING);
$info = gnupg_keyinfo($res, 'your-key-id');
echo
"Key - Info<pre>";
var_dump($info);
echo
"</pre>";
?>
To Top