PHP: openssl_sign - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

openssl_verify openssl_seal

Last updated: Sat, 27 Jan 2007

view this page in

# openssl_sign

(PHP 4 >= 4.0.4, PHP 5)

openssl_sign -- Generate signature

## Description

bool openssl_sign ( string data, string &signature, mixed priv_key_id [, int signature_alg] )

Возвращает `TRUE` в случае успешного завершения или `FALSE` в случае возникновения ошибки. If successful the signature is returned in `signature`.

openssl_sign() computes a signature for the specified `data` by using SHA1 for hashing followed by encryption using the private key associated with `priv_key_id`. Note that the data itself is not encrypted.

> Замечание: Optional 4th parameter `signature_alg` was added in version 5.0.0. Its default value is `OPENSSL_ALGO_SHA1`. For more information see the list of Signature Algorithms.

Пример 1. openssl_sign() example

`<?php
// $data is assumed to contain the data to be signed
// fetch private key from file and ready it
$fp = fopen("/src/openssl-0.9.6/demos/sign/key.pem", "r");
$priv_key = fread($fp, 8192);
fclose($fp);
$pkeyid = openssl_get_privatekey($priv_key);
// compute signature
openssl_sign($data, $signature, $pkeyid);
// free the key from memory
openssl_free_key($pkeyid);
?>`

See also openssl_verify().

add a note User Contributed Notes
openssl_sign
adam dot mansfeld at gmail dot com
19-Oct-2005 12:50
`Hello,
the fourth parameter 'signature_alg' to choose the signature algorithm can be one of:
OPENSSL_ALGO_SHA1
OPENSSL_ALGO_MD5
OPENSSL_ALGO_MD4
OPENSSL_ALGO_MD2
Just for the case that somebody needs this.
Regards`
add a note
openssl_verify openssl_seal

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST