国密 GMSSL+openssl+openresty 安装、配置、使用(超详细)

国密安装-配置-使用

  • 从刚装完虚拟机开始
1. 安装所需依赖 :
vi /etc/apt/sources.list
#简单可用(某些依赖包需要从官网上拉取)
deb http://mirrors.163.com/debian/ stretch main
deb-src http://mirrors.163.com/debian/ stretch main

deb http://security.debian.org/debian-security stretch/updates main contrib
deb-src http://security.debian.org/debian-security stretch/updates main contrib

#更新并安装依赖
apt-get update
apt-get upgrade
apt-get install gcc g++ make cmake unzip net-tools wget vim luajit
2. 下载安装包
wget https://www.openssl.org/source/openssl-1.1.1h.tar.gz
wget https://github.com/guanzhi/GmSSL/archive/refs/heads/GmSSL-v2.zip
wget http://zlib.net/zlib-1.2.13.tar.gz
wget https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz
wget https://openresty.org/download/openresty-1.19.3.1.tar.gz
3. 升级OpenSSL 旧版本

自带的1.1.0d版支持的算法不全,1.1.1较全面

tar zxvf openssl-1.1.1h.tar.gz
cd openssl-1.1.1h
./config
make && make install 
#备份原openssl
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak
#添加软连接	
ln -s /usr/local/bin/openssl /usr/bin/openssl
ln -s /usr/local/include/openssl/ /usr/include/openssl
#可以用which openssl命令查看路径,如果有神通数据库则路径如下:/opt/ShenTong/bin/openssl
ln -s /usr/bin/openssl /opt/ShenTong/bin/openssl
#将新的库文件地址写入记录so库的配置文件
echo "/usr/local/lib64" >> /etc/ld.so.conf
#设置生效
ldconfig -v
4. 解压-编译安装
tar zxvf zlib-1.2.13.tar.gz
cd zlib-1.2.13
./configure && make && make install
-----------------------------------------------------------------  
tar zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure \
--prefix=/usr/local/pcre
make && make install
-------------------------------------------------------------------- 
unzip GmSSL-v2.zip
cd GmSSL-GmSSL-v2
./config --prefix=/usr/local/gmssl no-shared
make && make install
#添加环境变量
$echo 'export PATH="$PATH:/usr/local/gmssl/bin"' >> ~/.bash_profile
$source ~/.bash_profile
---------------------------------------------------------------------------
tar zxvf openresty-1.19.3.1.tar.gz
cd openresty-1.19.3.1
./configure \
 --prefix=/usr/local/openresty \
 --with-http_ssl_module \
 --with-http_v2_module \
 --with-stream_ssl_preread_module \
 --with-cc-opt="-I/usr/local/gmssl/include -I/usr/local/pcre/include" \
 --with-ld-opt="-L/usr/local/gmssl/lib -L/usr/local/pcre/lib"
--------------------------------------------------------------------------
make
make install
---------------------------------------------------------------------------
 export PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
5. 生成证书测试
mkdir gmtest
cd gmtest
mkdir certs crl newcerts private
touch index.txt
echo "01" > serial

将openssl.cnf 导入gmtest路径下 openssl.cnf文件

[ ca ]
default_ca	= CA_default		# The default ca section

####################################################################
[ CA_default ]

dir		= .		# Where everything is kept
certs		= $dir/certs		# Where the issued certs are kept
crl_dir		= $dir/crl		# Where the issued crl are kept
database	= $dir/index.txt	# database index file.
#unique_subject	= no			# Set to 'no' to allow creation of
					# several certs with same subject.
new_certs_dir	= $dir/newcerts		# default place for new certs.

certificate	= $dir/ca.crt 	# The CA certificate
serial		= $dir/serial 		# The current serial number
crlnumber	= $dir/crlnumber	# the current crl number
					# must be commented out to leave a V1 CRL
crl		= $dir/crl.pem 		# The current CRL
private_key	= $dir/private/ca.key # The private key
RANDFILE	= $dir/private/.rand	# private random number file

x509_extensions	= usr_cert		# The extensions to add to the cert

# Comment out the following two lines for the "traditional"
# (and highly broken) format.
name_opt 	= ca_default		# Subject Name options
cert_opt 	= ca_default		# Certificate field options

# Extension copying option: use with caution.
# copy_extensions = copy

# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
# so this is commented out by default to leave a V1 CRL.
# crlnumber must also be commented out to leave a V1 CRL.
# crl_extensions	= crl_ext

default_days	= 365			# how long to certify for
default_crl_days= 30			# how long before next CRL
default_md	= sm3		# use public key default MD
preserve	= no			# keep passed DN ordering

# A few difference way of specifying how similar the request should look
# For type CA, the listed attributes must be the same, and the optional
# and supplied fields are just that :-)
policy		= policy_anything
distinguished_name = req_distinguished_name
# For the CA policy
#[ policy_match ]
#countryName		= match
#stateOrProvinceName	= match
#organizationName	= match

#organizationalUnitName	= optional
#commonName		= supplied
#emailAddress		= optional

# For the 'anything' policy
# At this point in time, you must list all acceptable 'object'
# types.
[ policy_anything ]
countryName		= optional
stateOrProvinceName	= optional
localityName		= optional
organizationName	= optional
organizationalUnitName	= optional
commonName		= supplied
emailAddress		= optional

####################################################################
[ req ]
default_bits		= 4096
default_md              = sm3
default_keyfile 	= privkey.pem
distinguished_name	= req_distinguished_name
#attributes		= req_attributes
x509_extensions	= v3_ca	# The extensions to add to the self signed cert
string_mask             = nombstr
# Passwords for private keys if not present they will be prompted for
# input_password = secret
# output_password = secret

# This sets a mask for permitted string types. There are several options.
# default: PrintableString, T61String, BMPString.
# pkix	 : PrintableString, BMPString (PKIX recommendation before 2004)
# utf8only: only UTF8Strings (PKIX recommendation after 2004).
# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
# MASK:XXXX a literal mask value.
# WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings.
#string_mask = utf8only

# req_extensions = v3_req # The extensions to add to a certificate request
###################################################################################

[ ssl_server ]
basicConstraints      = CA:FALSE
nsCertType            = server
keyUsage              = digitalSignature, keyEncipherment
extendedkeyUsage      = serverAuth, nsSGC, msSGC
nsComment             = "OpenSSL Certificate for SSL wed Server"

[ ssl_client ]
basicConstraints      = CA:FALSE
nsCertType            = client             
keyUsage              = digitalSignature, keyEncipherment
extendedkeyUsage      = clientAuth
nsComment             = "OpenSSL Certificate for SSL Client"

[ server_single_cert ]
basicConstraints=CA:FALSE
nsCertType = server
keyUsage = nonRepudiation,digitalSignature,keyEncipherment,dataEncipherment,keyAgreement

[ server_sign_cert ]
basicConstraints=CA:FALSE
nsCertType = server
keyUsage = nonRepudiation,digitalSignature

[ server_enc_cert ]
basicConstraints=CA:FALSE
nsCertType = server
keyUsage   = keyEncipherment,dataEncipherment,keyAgreement

[ client_single_cert ]
basicConstraints = CA:FALSE
nsCertType   =  client
keyUsage     =  nonRepudiation,digitalSignature,keyEncipherment,dataEncipherment,keyAgreement

[ client_sign_cert ]
basicConstraints = CA:FALSE
nsCertType = client
keyUsage   = nonRepudiation,digitalSignature

[ client_enc_cert ]
basicConstraints = CA:FALSE
nsCertType = client
keyUsage = keyEncipherment,dataEncipherment,keyAgreement


###################################################################################
#[ req_distinguished_name ]
#countryName			= Country Name (2 letter code)
#countryName_default		= CN
#countryName_min			= 2
#countryName_max			= 2

#stateOrProvinceName		= State or Province Name (full name)
#stateOrProvinceName_default	= Some-State

#localityName			= Locality Name (eg, city)

#0.organizationName		= Organization Name (eg, company)
#0.organizationName_default	= Internet Widgits Pty Ltd

# we can do this but it is not needed normally :-)
#1.organizationName		= Second Organization Name (eg, company)
#1.organizationName_default	= World Wide Web Pty Ltd

#organizationalUnitName		= Organizational Unit Name (eg, section)
#organizationalUnitName_default	=

#commonName			= Common Name (e.g. server FQDN or YOUR name)
#commonName_max			= 64

#emailAddress			= Email Address
#emailAddress_max		= 64

# SET-ex3			= SET extension number 3

#[ req_attributes ]
#challengePassword		= A challenge password
#challengePassword_min		= 4
#challengePassword_max		= 20

#unstructuredName		= An optional company name

#[ usr_cert ]

# These extensions are added when 'ca' signs a request.

# This goes against PKIX guidelines but some CAs do it and some software
# requires this to avoid interpreting an end user certificate as a CA.

#basicConstraints=CA:FALSE

# Here are some examples of the usage of nsCertType. If it is omitted
# the certificate can be used for anything *except* object signing.

# This is OK for an SSL server.
# nsCertType			= server

# For an object signing certificate this would be used.
# nsCertType = objsign

# For normal client use this is typical
# nsCertType = client, email

# and for everything including object signing:
# nsCertType = client, email, objsign

# This is typical in keyUsage for a client certificate.
# keyUsage = nonRepudiation, digitalSignature, keyEncipherment
# keyUsage = digitalSignature
#keyUsage = keyEncipherment

# This will be displayed in Netscape's comment listbox.
#nsComment			= "GmSSL Generated Certificate"

# PKIX recommendations harmless if included in all certificates.
#subjectKeyIdentifier=hash
#authorityKeyIdentifier=keyid,issuer

# This stuff is for subjectAltName and issuerAltname.
# Import the email address.
# subjectAltName=email:copy
# An alternative to produce certificates that aren't
# deprecated according to PKIX.
# subjectAltName=email:move

# Copy subject details
# issuerAltName=issuer:copy

#nsCaRevocationUrl		= http://www.domain.dom/ca-crl.pem
#nsBaseUrl
#nsRevocationUrl
#nsRenewalUrl
#nsCaPolicyUrl
#nsSslServerName

# This is required for TSA certificates.
# extendedKeyUsage = critical,timeStamping

#[ v3_req ]

# Extensions to add to a certificate request

#basicConstraints = CA:FALSE
#keyUsage = nonRepudiation, digitalSignature, keyEncipherment

[ v3_ca ]

# Extensions for a typical CA
# PKIX recommendation.

subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer
basicConstraints = critical,CA:true

# Key usage: this is typical for a CA certificate. However since it will
# prevent it being used as an test self-signed certificate it is best
# left out by default.
# keyUsage = cRLSign, keyCertSign

# Some might want this also
# nsCertType = sslCA, emailCA

# Include email address in subject alt name: another PKIX recommendation
# subjectAltName=email:copy
# Copy issuer details
# issuerAltName=issuer:copy

# DER hex encoding of an extension: beware experts only!
# obj=DER:02:03
# Where 'obj' is a standard or added object
# You can even override a supported extension:
# basicConstraints= critical, DER:30:03:01:01:FF

#[ crl_ext ]

# CRL extensions.
# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.

# issuerAltName=issuer:copy
#authorityKeyIdentifier=keyid:always

#[ proxy_cert_ext ]
# These extensions should be added when creating a proxy certificate

# This goes against PKIX guidelines but some CAs do it and some software
# requires this to avoid interpreting an end user certificate as a CA.

#basicConstraints=CA:FALSE

# Here are some examples of the usage of nsCertType. If it is omitted
# the certificate can be used for anything *except* object signing.

# This is OK for an SSL server.
# nsCertType			= server

# For an object signing certificate this would be used.
# nsCertType = objsign

# For normal client use this is typical
# nsCertType = client, email

# and for everything including object signing:
# nsCertType = client, email, objsign

# This is typical in keyUsage for a client certificate.
# keyUsage = nonRepudiation, digitalSignature, keyEncipherment

# This will be displayed in Netscape's comment listbox.
#nsComment			= "GmSSL Generated Certificate"

# PKIX recommendations harmless if included in all certificates.
#subjectKeyIdentifier=hash
#authorityKeyIdentifier=keyid,issuer

# This stuff is for subjectAltName and issuerAltname.
# Import the email address.
# subjectAltName=email:copy
# An alternative to produce certificates that aren't
# deprecated according to PKIX.
# subjectAltName=email:move

# Copy subject details
# issuerAltName=issuer:copy

#nsCaRevocationUrl		= http://www.domain.dom/ca-crl.pem
#nsBaseUrl
#nsRevocationUrl
#nsRenewalUrl
#nsCaPolicyUrl
#nsSslServerName

# This really needs to be in place for it to be a proxy certificate.
#proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo

####################################################################
#[ tsa ]

#default_tsa = tsa_config1	# the default TSA section

#[ tsa_config1 ]

# These are used by the TSA reply generation only.
#dir		= .		# TSA root directory
#serial		= $dir/tsaserial	# The current serial number (mandatory)
#crypto_device	= builtin		# OpenSSL engine to use for signing
#signer_cert	= $dir/tsacert.pem 	# The TSA signing certificate
					# (optional)
#certs		= $dir/cacert.pem	# Certificate chain to include in reply
					# (optional)
#signer_key	= $dir/private/tsakey.pem # The TSA private key (optional)
#signer_digest	= sm3			# Signing digest to use. (Optional)
#default_policy	= tsa_policy1		# Policy if request did not specify it
					# (optional)
#other_policies	= tsa_policy2, tsa_policy3		# acceptable policies (optional)
#digests		= sm3, sha256, sha384, sha512		# Acceptable message digests (mandatory)
#accuracy	= secs:1, millisecs:500, microsecs:100	# (optional)
#clock_precision_digits  = 0	# number of digits after dot. (optional)
#ordering		= yes	# Is ordering defined for timestamps?
				# (optional, default: no)
#tsa_name		= yes	# Must the TSA name be included in the reply?
				# (optional, default: no)
#ess_cert_id_chain	= no	# Must the ESS cert id chain be included?
				# (optional, default: no)

准备好如上环境后,进行证书生成

创建证书生成的目录:mkdir /root/gmtest cd /root/gmtest

(按照配置文件建好对应的目录结构后,即可进行证书的颁发,具体的颁发过程主要包含以下几步:)

#1.生成CA根证书所需私钥,指定生成私钥算法为sm2以及长度256位
$gmssl ecparam -genkey -name sm2p256v1 -out ca.key
$cp ca.key private/

#2.生成签发CA证书的证书请求,指定证书主题等信息
$gmssl req -new -sm3 -key ca.key -subj /C=CN/ST=Shan\ Xi/L=SH/O=CA/OU=CA/CN=ROOT\ CA/emailAddress=rootca@gmail.com -out ca.csr

#3.自签发CA根证书
$gmssl ca -selfsign -in ca.csr -out ca.crt -config openssl.cnf -extensions v3_ca 
-----------------------------------------------------------------------------------
(通过以上三步,我们就建立好了一个可以签发证书的CA。接下来即可使用该CA为通信测试的双方:服务器以及客户端,签发证书。)
国密SSL协议是双证书机制,因此需要签发签名证书与加密证书,具体的签发流程如下:

#1、创建服务器签名和加密密钥 (生成的私钥文件与ca私钥文件类似)
$gmssl ecparam -genkey -name sm2p256v1 -out server-sign.key
$gmssl ecparam -genkey -name sm2p256v1 -out server-enc.key

#2、创建服务器证书请求
$gmssl req -new -sm3 -key server-sign.key -subj /C=CN/ST=Shang\ Hai/L=SH/O=Server/OU=Server\ Sign/CN=172.16.150.8/emailAddress=server@gmail.com -out server-sign.csr
$gmssl req -new -sm3 -key server-enc.key -subj /C=CN/ST=Shang\ Hai/L=SH/O=Server/OU=Server\ Encrypt/CN=172.16.150.8/emailAddress=server@gmail.com -out server-enc.csr

#3、签发服务器双证书   (签名证书:密钥用途为数字签名  加密证书:密钥用途为加解密)
$gmssl ca -in server-sign.csr -keyfile ./private/ca.key -cert ca.crt -out server-sign.pem -extensions server_sign_cert -config openssl.cnf
$gmssl ca -in server-enc.csr -keyfile ./private/ca.key -cert ca.crt -out server-enc.pem -extensions server_enc_cert -config openssl.cnf

(通过以上三个步骤,即准备完成服务器所需密钥及证书,接下来签发客户端双证书的流程与上类似)
(通过上面的过程,目前已具备测试国密SSL协议的根证书,服务器客户端证书及私钥,接下来可以借助gmssl的s_server与s_client组件进行通信测试)
(通信测试需要开启两个终端,一个作为服务器,另一个作为客户端

#首先开启服务器端,进入监听状态,(其中 -gmtls参数指定通信协议类型,-key参数指定通信所需签名私钥,-cert参数指定签名证书,-dkey参数指定通信所需加密私钥,-dcert参数指定加密证书 -CAfile指定根证书 -verify参数证明开启双向认证,双向认证即为在通信过程中不仅客户端需要验证服务器身份,服务器也要验证客户端身份,保证双方可信)
$gmssl s_server -gmtls -key server-sign.key -cert server-sign.pem -dkey server-enc.key -dcert server-enc.pem -CAfile ca.crt -verify 1

下一步打开客户端进行连接。

(连接后服务器日志如下所示证明已有客户端成功连接,并通过SM2-WITH-SMS4-SM3算法套件协商成功)

(客户端日志如下所示:证明握手成功,验证通过,同时协商出主密钥。)
(接下来,服务器与客户端即可加密通信传输报文,通过下图表示通信测试成功)
( 以上即为国密CA的创建,国密证书签发以及国密SSL协议通信测试的完整流程,通信过程中使用的SM2-WITH-SMS4-SM3算法套件,GMTLS协议版本为1.1。)
6. openresty-nginx配置 nginx.conf文件
worker_processes  2;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen 80;
        listen 443 ssl;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:AES128-SHA:DES-CBC3-SHA:ECC-SM4-CBC-SM3:ECDHE-SM4-GCM-SM3:SM2-WITH-SMS4-SM3;
        ssl_verify_client off;
               
       # ssl_certificate /root/gmtest/ca.crt;
       # ssl_certificate_key /root/gmtest/ca.key;

        ssl_certificate /root/gmtest/server-enc.crt;
        ssl_certificate_key /root/gmtest/server-enc.key;

        ssl_certificate /root/gmtest/server-sign.crt;
        ssl_certificate_key /root/gmtest/server-sign.key;

        location / {
            root  /usr/local/openresty/nginx/html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {
            root   html;
        }
    }
}

开启nginx服务

$cd /usr/local/openresty/nginx

#编辑nginx.conf
$vim conf/nginx.conf

#验证并开启nginx
$./sbin/nginx

7. 服务器端验证
https://172.16.150.8
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: 国密SM2和SM3是中国自主研发的密码算法,用于保障信息安全。SM2是一种椭圆曲线公钥密码算法,主要用于数字签名和密钥交换。其使用逻辑如下: 首先,接收方需要生成一对公私钥对。生成方法为随机选择一个椭圆曲线,然后随机选择一个私钥,并计算对应的公钥。 发送方在发送消息之前需要获取接收方的公钥,并利用该公钥进行加密。具体的加密过程包括:首先选择一个随机数作为临时私钥,并利用接收方公钥计算出对应的临时公钥。然后,利用对称加密算法对待发送的消息进行加密,使用临时公钥对对称加密算法的密钥进行加密,并将临时公钥和加密后的消息一起发送给接收方。 接收方收到加密后的消息后,需要先用其私钥解密出加密算法的密钥,然后再用该密钥解密出原始消息。同时,接收方需要验证发送方的身份以及消息的完整性,这一点通过验证发送方的数字签名即可完成。接收方利用发送方的公钥验证数字签名的有效性,如果验证通过,则说明发送方身份真实可信,并且消息未被篡改。 SM3是一种密码杂凑算法,主要用于数据的完整性校验和身份认证。其使用逻辑如下: 对于发送方,首先将待处理的消息进行分组,然后利用SM3算法进行逐个分组的运算,得到一个最终的哈希值。该哈希值可以用于验证消息的完整性,因为即使是对原始消息做一个微小的改动,也会导致哈希值的剧烈变化。 对于接收方,首先接收到消息和对应的哈希值。接收方利用SM3算法对接收到的消息进行哈希运算,得到一个新的哈希值。然后,将此新的哈希值与发送方传递过来的哈希值进行比较,如果两个哈希值相等,则说明消息未被篡改,反之则说明消息可能被篡改。 综上所述,国密SM2和SM3使用一定的算法和逻辑来保障信息的安全性,包括加密、解密、数字签名、完整性校验等步骤,确保信息在传输过程中不被窃取、篡改或冒充。 ### 回答2: 国密是指中国自主研发的密码算法标准,其中包括了SM2和SM3算法。 SM2算法是一种非对称加密算法,使用公钥加密和私钥解密。使用逻辑如下: 1. 密钥生成:首先生成一对密钥,包括公钥和私钥。公钥用于加密,私钥用于解密。 2. 加密:发送方通过获取接收方的公钥,使用公钥对明文进行加密。加密后的密文只能通过私钥进行解密,确保传输安全性。 3. 解密:接收方使用私钥对收到的密文进行解密,得到原始的明文。 SM2算法的特点是安全性高,计算量相对较小,适合用于各种加密场景,如数据通信、数字签名、身份认证等。 SM3算法是一种哈希算法,用于生成消息摘要,保证信息完整性和不可篡改性。使用逻辑如下: 1. 输入消息:将待处理的消息输入到SM3算法中。 2. 分组处理:将消息分割为若干个固定长度的块,然后按照特定的算法对每个块进行处理。 3. 压缩函数:对每个块进行压缩函数的处理,得到一系列中间结果,然后利用这些结果生成最终的消息摘要。 4. 输出结果:生成的消息摘要作为结果输出,具有唯一性和不可逆性。 SM3算法的特点是抗碰撞性强,计算速度较快,适合用于数字签名、数据完整性校验等应用场景。 总之,国密的SM2和SM3算法分别用于非对称加密和哈希运算,可以保证数据的安全性和完整性。 ### 回答3: 国密是中国自主研发的密码算法标准。国密SM2和SM3分别是用于非对称加密和哈希算法的密码算法。下面将分别介绍SM2和SM3的使用逻辑。 SM2是一种非对称加密算法,它包括密钥生成、密钥交换、加密和解密等过程。首先,要使用SM2,需要生成一对密钥:公钥和私钥。公钥用于加密数据,私钥用于解密数据。生成密钥的过程包括选择一个大素数作为椭圆曲线的参数,然后选择一个基点,并在此基点上进行一系列的操作,最终得到公钥和私钥。 加密过程中,发送方使用接收方的公钥对数据进行加密。具体的过程是,发送方首先将明文数据转换为一个随机数,然后通过椭圆曲线上的运算将随机数转换为一个点(即加密数据),接着将该点与接收方的公钥进行一系列的运算,最后得到加密后的密文。 解密过程中,接收方使用自己的私钥对密文进行解密。具体的过程是,接收方首先通过椭圆曲线上的运算将密文点与私钥进行一系列的运算,得到加密数据点,然后再通过另一系列的运算将加密数据点转换为原始的随机数,最后将随机数转换为明文数据。 SM3是一种哈希算法,用于生成数据的哈希值。其使用逻辑包括数据填充、迭代压缩和最终运算等步骤。首先,要使用SM3,需要将待哈希的数据进行填充,使其满足一定的长度要求。填充后的数据被分成若干个分组,然后对每个分组进行迭代压缩。迭代压缩过程包括一系列的逻辑运算,如位运算、异或运算等。最后,对最后一个分组进行最终运算,得到哈希值。 综上所述,国密SM2和SM3使用的逻辑分别涉及非对称加密和哈希算法。使用SM2时,需要生成密钥对,发送方使用接收方的公钥对数据进行加密,接收方使用私钥进行解密。使用SM3时,需要对待哈希的数据进行填充,然后进行迭代压缩,并最终得到哈希值。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值