public function setKeyParams($algorithm, $size = 0, $usage = 0)
    {
        $algorithm = intval($algorithm);

        if ($algorithm === Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC) {
            throw new Crypt_GPG_InvalidKeyParamsException(
                'Primary key algorithm must be capable of signing. The ' .
                'Elgamal algorithm can only encrypt.',
                0,
                $algorithm,
                $size,
                $usage
            );
        }

        if ($size != 0) {
            $size = intval($size);
        }

        if ($usage != 0) {
            $usage = intval($usage);
        }

        $usageEncrypt = Crypt_GPG_SubKey::USAGE_ENCRYPT;

        if ($algorithm === Crypt_GPG_SubKey::ALGORITHM_DSA
            && ($usage & $usageEncrypt) === $usageEncrypt
        ) {
            throw new Crypt_GPG_InvalidKeyParamsException(
                'The DSA algorithm is not capable of encrypting. Please ' .
                'specify a different algorithm or do not include encryption ' .
                'as a usage for the primary key.',
                0,
                $algorithm,
                $size,
                $usage
            );
        }

        $this->keyAlgorithm = $algorithm;

        if ($size != 0) {
            $this->keySize = $size;
        }

        if ($usage != 0) {
            $this->keyUsage = $usage;
        }

        return $this;
    }
public function setKeyParams($algorithm, $size = 0, $usage = 0)
    {
        $algorithm = intval($algorithm);

        if ($algorithm === Crypt_GPG_SubKey::ALGORITHM_ELGAMAL_ENC) {
            throw new Crypt_GPG_InvalidKeyParamsException(
                'Primary key algorithm must be capable of signing. The ' .
                'Elgamal algorithm can only encrypt.',
                0,
                $algorithm,
                $size,
                $usage
            );
        }

        if ($size != 0) {
            $size = intval($size);
        }

        if ($usage != 0) {
            $usage = intval($usage);
        }

        $usageEncrypt = Crypt_GPG_SubKey::USAGE_ENCRYPT;

        if ($algorithm === Crypt_GPG_SubKey::ALGORITHM_DSA
            && ($usage & $usageEncrypt) === $usageEncrypt
        ) {
            throw new Crypt_GPG_InvalidKeyParamsException(
                'The DSA algorithm is not capable of encrypting. Please ' .
                'specify a different algorithm or do not include encryption ' .
                'as a usage for the primary key.',
                0,
                $algorithm,
                $size,
                $usage
            );
        }

        $this->keyAlgorithm = $algorithm;

        if ($size != 0) {
            $this->keySize = $size;
        }

        if ($usage != 0) {
            $this->keyUsage = $usage;
        }

        return $this;
    }
public function setKeyParams ( $ algorithm , $ size = 0 , $ usage = 0 ) { $ algorithm = intval ( $ algorithm ) ; if ( $ algorithm === Crypt_GPG_SubKey :: ALGORITHM_ELGAMAL_ENC ) { throw new Crypt_GPG_InvalidKeyParamsException ( 'Primary key algorithm must be capable of signing. The ' . 'Elgamal algorithm can only encrypt.' , 0 , $ algorithm , $ size , $ usage ) ; } if ( $ size != 0 ) { $ size = intval ( $ size ) ; } if ( $ usage != 0 ) { $ usage = intval ( $ usage ) ; } $ usageEncrypt = Crypt_GPG_SubKey :: USAGE_ENCRYPT ; if ( $ algorithm === Crypt_GPG_SubKey :: ALGORITHM_DSA && ( $ usage & $ usageEncrypt ) === $ usageEncrypt ) { throw new Crypt_GPG_InvalidKeyParamsException ( 'The DSA algorithm is not capable of encrypting. Please ' . 'specify a different algorithm or do not include encryption ' . 'as a usage for the primary key.' , 0 , $ algorithm , $ size , $ usage ) ; } $ this -> keyAlgorithm = $ algorithm ; if ( $ size != 0 ) { $ this -> keySize = $ size ; } if ( $ usage != 0 ) { $ this -> keyUsage = $ usage ; } return $ this ; }
Sets the parameters for the primary key of generated key-pairs

@param integer $algorithm the algorithm used by the key. This should be
one of the Crypt_GPG_SubKey::ALGORITHM_*
constants.
@param integer $size      optional. The size of the key. Different
algorithms have different size requirements.
If not specified, the default size for the
specified algorithm will be used. If an
invalid key size is used, GnuPG will do its
best to round it to a valid size.
@param integer $usage     optional. A bitwise combination of key usages.
If not specified, the primary key will be used
only to sign and certify. This is the default
behavior of GnuPG in interactive mode. Use
the Crypt_GPG_SubKey::USAGE_* constants here.
The primary key may be used to certify even
if the certify usage is not specified.

@return Crypt_GPG_KeyGenerator the current object, for fluent interface.
Sets the parameters for the primary key of generated key - pairs