使用php-openssl为docx创建数字签名

时间:2014-04-01 18:45:16

标签: php encryption openssl digital-signature php-openssl

我需要为可填写的表单创建数字签名。这意味着当用户填写表单时,他必须签署文档。使用他自己的私钥,我们的服务器将使用公钥检查他的私钥。我研究了它,但我找不到真正的答案。我将使用php-openssl,表格将是可填写的。我可以使用此代码创建密钥对;

// generate 2048-bit RSA key    
$pkGenerate = openssl_pkey_new(array(

    'private_key_bits' => 2048,

    'private_key_type' => OPENSSL_KEYTYPE_RSA));

// get the private key    
openssl_pkey_export($pkGenerate,$pkGeneratePrivate);

// get the public key    
$pkGenerateDetails = openssl_pkey_get_details($pkGenerate);

$pkGeneratePublic = $pkGenerateDetails['key'];

// free resources    
openssl_pkey_free($pkGenerate);

// fetch/import public key from PEM formatted string    
// remember $pkGeneratePrivate now is PEM formatted...    
// this is an alternative method from the public retrieval in previous

$pkImport = openssl_pkey_get_private($pkGeneratePrivate); // import

$pkImportDetails = openssl_pkey_get_details($pkImport); // same as getting the public key in previous

$pkImportPublic = $pkImportDetails['key'];

openssl_pkey_free($pkImport); // clean up

echo "\n".$pkGeneratePrivate

    ."\n".$pkGeneratePublic

    ."\n".$pkImportPublic

    ."\n".'Public keys are '.
(strcmp($pkGeneratePublic,$pkImportPublic)?'different':'identical').'.';

0 个答案:

没有答案