OpenSSL using the DSA algorithm to generate signatures

Source: Internet
Author: User
Tags openssl openssl sha1 sha1

Command:

openssl> dgst-dss1-sign c.pri-out Signature.bin s.txt

Explain

C.pri is the private key file generated by the DSA algorithm

S.txt is the original of the signature.

Signature.bin is the generated signature file

PHP can use the following methods to view the content of the signature

The code is as follows
<?php
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 Harlem values, while others produce 128-bit. It is recommended that you use SHA1 or RIPEMD-160 unless you are considering compatibility.

In addition to the RIPEMD-160 need to use the rmd160 command, other algorithms can be performed using the DGST command.

OpenSSL's handling of SHA1 is a bit odd, and sometimes it has to be referred to as DSS1.

The message digest algorithm can also be used for signing and verifying signatures in addition to calculating hasi values. When signing, the private key generated by DSA must be paired with DSS1 (i.e. SHA1). For RSA-generated private keys, any message digest algorithm can be used.

# Message digest Algorithm application example

# using the SHA1 algorithm to calculate the file.txt value of the file, output to stdout

$ OpenSSL dgst-sha1 file.txt

# using the SHA1 algorithm to calculate the file.txt value of the file, the output to the file Digest.txt

$ OpenSSL sha1-out digest.txt file.txt

# with DSS1 (SHA1) algorithm for file file.txt signature, output to file Dsasign.bin

# The private key of the signature must be generated for the DSA algorithm, saved in the file Dsakey.pem

$ OpenSSL dgst-dss1-sign dsakey.pem-out dsasign.bin file.txt

# using the DSS1 algorithm to verify the file.txt digital signature Dsasign.bin,

# Authenticated private key is a file generated by the DSA algorithm DSAKEY.PEM

$ OpenSSL dgst-dss1-prverify dsakey.pem-signature dsasign.bin file.txt

# with SHA1 algorithm for file file.txt signature, output to file Rsasign.bin

# The private key for the signature is the file generated by the RSA algorithm RSAPRIVATE.PEM

$ OpenSSL sha1-sign rsaprivate.pem-out rsasign.bin file.txt

# using the SHA1 algorithm to verify the file.txt digital signature Rsasign.bin,

# Authenticated public key for RSA algorithm-generated RSAPUBLIC.PEM

$ OpenSSL sha1-verify rsapublic.pem-signature rsasign.bin file.txt

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.