search
HomeBackend DevelopmentPHP TutorialDetailed explanation of how openssl uses DSA algorithm to generate signature examples_PHP tutorial
Detailed explanation of how openssl uses DSA algorithm to generate signature examples_PHP tutorialJul 13, 2016 am 10:48 AM
dsaopensslintroduceusebased onExamplearticlegeneratesignalgorithmDetailed explanation

The article introduces you to an example of using the DSA algorithm to generate a signature based on openssl. The method of generating a signature is very simple, but we need to understand the middle principle, which is more complicated. Let's take a look.

Command:

openssl> dgst -dss1 -sign C.pri -out signature.bin s.txt

Explanation
C.pri is the private key file generated by the DSA algorithm
s.txt is the original text for making the signature
signature.bin is the generated signature file

You can use the following method to view the signature content in php

# Use the sha1 algorithm to sign the file file.txt and output it to the file rsasign.bin # The private key of the signature is the file rsaprivate.pem
The code is as follows
 代码如下 复制代码
echo bin2hex(file_get_contents('signature.bin'));
?>
Copy code


echo bin2hex(file_get_contents('signature.bin'));
?>

Reference content
Message Digest Algorithm
Supported algorithms include: MD2, MD4, MD5, MDC2, SHA1 (sometimes called DSS1), RIPEMD-160. SHA1 and RIPEMD-160 produce 160-bit hashes, the others produce 128-bit hashes. Unless for compatibility reasons, it is recommended to use SHA1 or RIPEMD-160.
Except for RIPEMD-160, which requires the rmd160 command, other algorithms can be executed with the dgst command.
OpenSSL's handling of SHA1 is a bit strange, and sometimes it must be referred to as DSS1.
In addition to calculating hash values, the message digest algorithm can also be used to sign and verify signatures. When signing, the private key generated by DSA must be matched with DSS1 (ie SHA1). For private keys generated by RSA, any message digest algorithm can be used.

# Message Digest Algorithm Application Example
# Use SHA1 algorithm to calculate the hash value of file file.txt and output it to stdout
$ openssl dgst -sha1 file.txt
# Use the SHA1 algorithm to calculate the hash value of the file file.txt and output it to the file digest.txt
$ openssl sha1 -out digest.txt file.txt
# Use the DSS1 (SHA1) algorithm to sign the file file.txt and output it to the file dsasign.bin
# The private key of the signature must be generated by the DSA algorithm and stored in the file dsakey.pem
$ openssl dgst -dss1 -sign dsakey.pem -out dsasign.bin file.txt
# Use dss1 algorithm to verify the digital signature dsasign.bin of file.txt,
# The private key to be verified is the file dsakey.pem

generated by the DSA algorithm $ openssl dgst -dss1 -prverify dsakey.pem -signature dsasign.bin file.txt
generated by the RSA algorithm $ openssl sha1 -sign rsaprivate.pem -out rsasign.bin file.txt # Use sha1 algorithm to verify the digital signature of file.txt rsasign.bin,

# The verified public key is rsapublic.pem

generated by RSA algorithm $ openssl sha1 -verify rsapublic.pem -signature rsasign.bin file.txt http://www.bkjia.com/PHPjc/632818.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/632818.html
TechArticle
The article introduces an example of using the DSA algorithm to generate a signature based on openssl. The method of generating a signature is very simple. We need to understand the middle The principle is more complicated, let’s take a look together. ...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Nginx如何使用OpenSSL库实现更安全的通信Nginx如何使用OpenSSL库实现更安全的通信Jun 10, 2023 pm 01:51 PM

Nginx是一款广泛应用于Web服务器、负载均衡器、反向代理和缓存的软件。在网络传输过程中,数据的加密和安全性越来越受到关注。为了提高通信的安全性,可以使用OpenSSL库来实现SSL/TLS协议,从而保护敏感数据的传输。本文将讲解如何使用Nginx与OpenSSL库实现更安全的通信。安装与配置OpenSSL库首先,需要在服务器上安装OpenSSL库。可以使

如何在Go中使用命名管道?如何在Go中使用命名管道?May 11, 2023 pm 04:22 PM

命名管道是一种在操作系统中相对比较低级的进程通信方式,它是一种以文件为中介的进程通信方式。在Go语言中,通过os包提供了对命名管道的支持。在本文中,我们将介绍如何在Go中使用命名管道来实现进程间通信。一、命名管道的概念命名管道是一种特殊的文件,可以被多个进程同时访问。在Linux系统中,命名管道是一种特殊的文件类型,它们存在于文件系统的某个位置上,并且可以在

如何使用 OpenSSL 生成 MySQL SSL 证书如何使用 OpenSSL 生成 MySQL SSL 证书Sep 09, 2023 pm 02:12 PM

如何使用OpenSSL生成MySQLSSL证书简介:MySQL是一种广泛应用的关系型数据库系统,在实际生产环境中使用SSL(SecureSocketsLayer)协议进行加密通信是非常重要的。本文将介绍如何使用OpenSSL工具生成MySQLSSL证书,并提供相应的代码示例。步骤:安装OpenSSL:首先,确保计算机上已安装O

CentOS 7下OpenBLAS安装及CentOS 7 OpenSSL安装CentOS 7下OpenBLAS安装及CentOS 7 OpenSSL安装Feb 10, 2024 am 11:45 AM

LINUX作为一个开源操作系统,有着广泛的应用和用户群体,CentOS7是LINUX的一个分支版本,它是基于RedHatEnterpriseLinux(RHEL)源代码构建的,具有高度的稳定性和安全性,在CentOS7上安装和配置OpenBLAS和OpenSSL是许多开发者和系统管理员的常见需求,本文将详细介绍如何在CentOS7上安装和配置OpenBLAS和OpenSSL。OpenBLAS是一个开源的基于BLAS(BasicLinearAlgebraSubprograms)接口的高性能数学库,

如何在Go中使用第三方库?如何在Go中使用第三方库?May 11, 2023 pm 03:30 PM

在Go语言中,使用第三方库是非常方便的。许多优秀的第三方库和框架可以帮助我们快速地开发应用程序,同时也减少了我们自己编写代码的工作量。但是如何正确地使用第三方库,确保其稳定性和可靠性,是我们必须了解的一个问题。本文将从以下几个方面介绍如何使用第三方库,并结合具体例子进行讲解。一、第三方库的获取Go语言中获取第三方库有以下两种方式:1.使用goget命令首先

如何在PHP中使用协程?如何在PHP中使用协程?May 12, 2023 am 08:10 AM

随着传统的多线程模型在高并发场景下的性能瓶颈,协程成为了PHP编程领域的热门话题。协程是一种轻量级的线程,能够在单线程中实现多任务的并发执行。在PHP的语言生态中,协程得到了广泛的应用,比如Swoole、Workerman等框架就提供了对协程的支持。那么,如何在PHP中使用协程呢?本文将介绍一些基本的使用方法以及常见的注意事项,帮助读者了解协程的运作原理,以

如何在Go中使用音频处理?如何在Go中使用音频处理?May 11, 2023 pm 04:37 PM

随着音频处理在各种应用场景中的普及,越来越多的程序员开始使用Go编写音频处理程序。Go语言作为一种现代化的编程语言,具有优秀的并发性和高效率的特点,使用它进行音频处理十分方便。本文将介绍如何在Go中使用音频处理技术,包括读取、写入、处理和分析音频数据等方面的内容。一、读取音频数据在Go中读取音频数据有多种方式。其中比较常用的是使用第三方库进行读取,比如go-

如何在 Windows 11 中按需使用 OneDrive 的文件如何在 Windows 11 中按需使用 OneDrive 的文件Apr 14, 2023 pm 12:34 PM

<p>Windows 系统上的 OneDrive 应用程序允许您将文件存储在高达 5 GB 的云上。OneDrive 应用程序中还有另一个功能,它允许用户选择一个选项,是将文件保留在系统空间上还是在线提供,而不占用您的系统存储空间。此功能称为按需文件。在这篇文章中,我们进一步探索了此功能,并解释了有关如何在 Windows 11 电脑上的 OneDrive 中按需使用文件的各种选项。</p><h2>如何使用 On

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools