略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Clearsign text

2024-12-22

Clearsign text

This example will clearsign a given text.

示例 #1 gnupg clearsign example (procedural)

<?php
// init gnupg
$res gnupg_init();
// not really needed. Clearsign is default
gnupg_setsignmode($res,GNUPG_SIG_MODE_CLEAR);
// add key with passphrase 'test' for signing
gnupg_addsignkey($res,"8660281B6051D071D94B5B230549F9DC851566DC","test");
// sign
$signed gnupg_sign($res,"just a test");
echo 
$signed;
?>

示例 #2 gnupg clearsign example (OO)

<?php
// new class
$gnupg = new gnupg();
// not really needed. Clearsign is default
$gnupg->setsignmode(gnupg::SIG_MODE_CLEAR);
// add key with passphrase 'test' for signing
$gnupg->addsignkey("8660281B6051D071D94B5B230549F9DC851566DC","test");
// sign
$signed $gnupg->sign("just a test");
echo 
$signed;
?>

示例 #3 keylistiterator

This extension also comes with an Iterator for your keyring.

<?php
// create a new iterator for listing all public keys that matches 'example'
$iterator = new gnupg_keylistiterator("example");
foreach(
$iterator as $fingerprint => $userid){
    echo 
$fingerprint." -> ".$userid."\n";
}
?>
add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/gnupg.examples-clearsign.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3