如何使用PHP将数字签名(RSA,证书等)添加到任何文件中? [英] How to add digital signature (RSA, Certificate, etc) to any of file, using PHP?

查看:154
本文介绍了如何使用PHP将数字签名(RSA,证书等)添加到任何文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道是否可以使用RSA,证书以及类似的东西对任何类型的文件进行数字签名,或者是否只能对某些类型的文件进行签名.所有这些,使用PHP.

I need to know if any kind of file can be signed digitally, using RSA, a certificate, and that stuff, or if only certain kind of files can be signed. All this, using PHP.

例如:可以对纯文本文件进行数字签名吗?图像(png,jpeg,bmp)如何?

In example: Can a plain text file be signed digitally?, What about images (png, jpeg, bmp)?

我不需要附加"带有图形签名的图像.

I don't need to "attach" an image with a graphic signature.

谢谢您的帮助.

推荐答案

使用 phpseclib,纯PHP RSA实现(已更新此处):

<?php
include('Crypt/RSA.php');

$rsa = new Crypt_RSA();
extract($rsa->createKey());

$plaintext = 'terrafrost';

$rsa->loadKey($privatekey);
$signature = $rsa->sign($plaintext);

$rsa->loadKey($publickey);
echo $rsa->verify($plaintext, $signature) ? 'verified' : 'unverified';
?>

与CLI openssl类似,如下所示:

The analog to that with the CLI openssl is as follows:

openssl dgst -sha1 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1 -out signature.txt -sign privatekey.txt plaintext.txt 
openssl dgst -sha1 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1 -prverify privatekey.txt -signature signature.txt plaintext.txt 

这篇关于如何使用PHP将数字签名(RSA,证书等)添加到任何文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆