CN114520724A - 一种开放api接口的签名验证方法 - Google Patents
一种开放api接口的签名验证方法 Download PDFInfo
- Publication number
- CN114520724A CN114520724A CN202210153455.1A CN202210153455A CN114520724A CN 114520724 A CN114520724 A CN 114520724A CN 202210153455 A CN202210153455 A CN 202210153455A CN 114520724 A CN114520724 A CN 114520724A
- Authority
- CN
- China
- Prior art keywords
- access
- request
- signature
- verification method
- key
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000012795 verification Methods 0.000 title claims abstract description 34
- 238000000034 method Methods 0.000 title claims abstract description 24
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 230000002950 deficient Effects 0.000 description 1
- 238000001914 filtration Methods 0.000 description 1
- 238000004519 manufacturing process Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L9/00—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
- H04L9/32—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials
- H04L9/3247—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials involving digital signatures
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L9/00—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
- H04L9/32—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials
- H04L9/321—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials involving a third party or a trusted authority
- H04L9/3213—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials involving a third party or a trusted authority using tickets or tokens, e.g. Kerberos
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L9/00—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols
- H04L9/32—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials
- H04L9/3236—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials using cryptographic hash functions
- H04L9/3239—Cryptographic mechanisms or cryptographic arrangements for secret or secure communications; Network security protocols including means for verifying the identity or authority of a user of the system or for message authentication, e.g. authorization, entity authentication, data integrity or data verification, non-repudiation, key authentication or verification of credentials using cryptographic hash functions involving non-keyed hash functions, e.g. modification detection codes [MDCs], MD5, SHA or RIPEMD
Landscapes
- Engineering & Computer Science (AREA)
- Computer Security & Cryptography (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Storage Device Security (AREA)
Abstract
本发明公开了一种开放API接口的签名验证方法,包括步骤S1:请求端向API平台发送数据参数请求;步骤S2:API平台根据请求生成带时间戳和随机字符串的密钥,根据所述秘钥对所述数据参数进行签名处理,并将秘钥和签名发送给请求端;步骤S3:请求端访问所述API平台,API平台对所述访问进行拦截,并判断所述访问是否包含所述时间戳和随机字符串,否则则访问失败,是则进一步判断所述访问是否包含所述签名,是则进行步骤S4,否则则访问失败;步骤S4:验证所述签名,验证成功则允许所述请求端访问所述参数对应的数据,验证不成功则访问失败。本发明实现了保证了API平台请求来源身份合法,请求参数无法修改,防止了请求重复。
Description
技术领域
本发明涉及计算机软件领域,尤其涉及的是一种开放API接口的签名验证方法。
背景技术
现在越来越多的平台提供了自身的API接口平台给其他方使用,以方便增加用户粘性,壮大自身生态建设,自己服务的传播,当在接口被调用的同时,也需要也需要防止本身的数据被窃取,数据被篡改,数据泄露等一系列安全问题。
通常API平台未添加接口验证方案,导致数据泄露,接口裸露,暴力攻击,导致平台不可用,或者一些重复请求未过滤处理。
因此,现有技术存在缺陷,需要改进。
发明内容
本发明所要解决的技术问题是:提供一种保证了API平台请求来源身份合法,请求参数无法修改,并且,防止了请求重复的开放API接口的签名验证方法。
本发明的技术方案如下:一种开放API接口的签名验证方法,包括如下步骤:步骤S1:请求端向API平台发送数据参数请求;步骤S2:API平台根据请求生成带时间戳和随机字符串的密钥,并且,根据所述秘钥,对所述数据参数进行签名处理,并将秘钥和签名发送给请求端;步骤S3:请求端访问所述API平台,API平台对所述访问进行拦截,并判断所述访问是否包含所述时间戳和随机字符串,否则则访问失败,是则进一步判断所述访问是否包含所述签名,是则进行步骤S4,否则则访问失败;步骤S4:验证所述签名,验证成功则允许所述请求端访问所述参数对应的数据,验证不成功则访问失败。
应用于上述技术方案,所述的开放API接口的签名验证方法中,在所述步骤S2中,对所述数据参数进行签名处理具体包括:在原始的参数上拼接所述秘钥,并且,对拼接秘钥后的参数进行MD5加密。
应用于上述各个技术方案,所述的开放API接口的签名验证方法中,在所述步骤S3中,在判断所述访问是否包含所述签名后,还判断所述访问是否为超时访问,是则访问失败,否则进行步骤S4。
应用于上述各个技术方案,所述的开放API接口的签名验证方法中,在所述步骤S3中,在判断所述访问是否包含所述签名前,还判断所述访问是否包含请求端的访问令牌token;是则在判断所述访问不是为超时访问后,根据所述访问令牌token,确定所述请求端的用户唯一身份标识uid,否则访问失败。
应用于上述各个技术方案,所述的开放API接口的签名验证方法中,还根据所述用户唯一身份标识uid,确定所述请求端为合法请求端来源,当确定所述请求端不是为合法请求端来源时,则访问失败。
应用于上述各个技术方案,所述的开放API接口的签名验证方法中,访问失败失败后,还返回一错误码给所述请求端。
应用于上述各个技术方案,所述的开放API接口的签名验证方法中,步骤S4中,验证所述签名成功后,记录该次访问验证履历。
本发明的有益效果为:
本发明通过判断访问是否包含请求端的访问令牌token,通过所述访问令牌token,确定所述请求端的用户唯一身份标识uid,保证了API平台请求来源身份合法,并且,通过对请求端的数据参数进行签名处理,使得请求参数无法修改,并且,利用时间戳和随机字符串,防止了请求重复进行。
附图说明
图1为本发明的请求端访问API接口的流程图。
具体实施方式
以下结合附图和具体实施例,对本发明进行详细说明。
本实施例提供了一种开放API接口的签名验证方法,如图1所示,签名验证方法包括如下步骤:步骤S1:请求端向API平台发送数据参数请求;然后步骤S2:API平台在收到请求端的数据参数请求时,API平台根据请求生成带时间戳和随机字符串的密钥,并且,根据所述秘钥,对所述数据参数进行签名处理,并将秘钥和签名发送给请求端;其中,由API平台为使用者(通常为开发人员)提供AccessKey/SecretKey,AccessKey通过唯一字符串生成策略保证唯一,SecretKey用于接口加密,生产算法保密,由API平台自主设计。
并且,对所述数据参数进行签名处理具体包括:在原始的参数上拼接所述秘钥,并且,对拼接秘钥后的参数进行MD5加密;其中对请求的数据参数,按参数名排序包括AccessKey;通过url键值对形式key1=value1&key2=value2..,获取到的字符串stringTemp;stringTemp最后拼接平台申请的SecretKey值为stringSignTemp;对stringSignTemp进行MD5运算,并且全部转大写,得到签名sign;例如:原始参数:string="AccessKey=key&name=zhangsan×tamp=now&nonce=n";
拼接密钥SecretKey:stringSignTemp="AccessKey=key&name=zhangsan×tamp=now&nonce=n&SecretKey=secret";
MD5加密:sign=MD5(stringSignTemp).toUpperCase();
然后,进行步骤S3:请求端访问所述API平台,API平台对所述访问进行拦截,并判断所述访问是否包含所述时间戳timestamp和随机字符串nonce,nonce指的是唯一随机字符串,标识每个被签名过的请求,通过对每次请求提供一个唯一的标识符,保证API平台能够防止请求多次,并且记录nonce防止重复使用。进行判断后,如果包含所述时间戳timestamp和随机字符串nonce,则进一步判断所述访问是否包含所述签名sign,如果不含包所述时间戳timestamp和随机字符串nonce,则访问请求失败,返回一个错误码给请求端;在判断所述访问是否包含所述签名前,还判断所述访问是否包含请求端的访问令牌token,如果不包含访问令牌token,则访问请求失败,返回一个错误码给请求端;以及在判断包含所述签名sign和访问令牌token之后,进一步判断所述访问是否为超时访问;当当前访问时间为正常时间后,再根据所述访问令牌token,确定所述请求端的用户唯一身份标识uid;当访问时间超时时,则访问请求失败,返回一个错误码给请求端。
在判断所述访问是否包含所述签名前,还判断所述访问是否包含请求端的访问令牌token;是则在判断所述访问不是为超时访问后,根据所述访问令牌token,确定所述请求端的用户唯一身份标识uid;根据所述用户唯一身份标识uid,确定所述请求端为合法请求端来源;其具体可以通过预先将合法请求端来源的用户唯一身份标识uid预存储在API平台中;如此,可以使API平台快速根据所述用户唯一身份标识uid判断请求端是否为合法请求端来源;如果不是合法请求端则访问请求失败,返回一个错误码给请求端。
最后,步骤S4:验证所述签名,其中,验证所述签名可以根据原始参数和拼接秘钥,以及MD5解密进行验证,如果验证成功则允许所述请求端访问所述参数对应的数据;如果验证失败,返回一个错误码给请求端。并且,验证所述签名成功后,记录该次访问验证履历。如此,通过新增了用户认证,保证了API平台请求来源身份合法;通过签名使得参数无法被篡改;利用时间戳和随机字符串nonce防止了请求重复。
可以解决数据安全问题:通过访问签名机制保证API平台安全稳定。重复请求:通过时间戳和超时时间,对有效请求处理,重复请求直接过滤。请求身份不合法:通过增加身份认证方案,确定请求是否合法,通过密钥为开发者新增accessKey(接入方身份,确保唯一)和SecretKey(用于接口加密)保证其合法。请求参数被篡改:通过加密算法对数据进行处理。
以上仅为本发明的较佳实施例而已,并不用于限制本发明,凡在本发明的精神和原则之内所作的任何修改、等同替换和改进等,均应包含在本发明的保护范围之内。
Claims (7)
1.一种开放API接口的签名验证方法,其特征在于,包括如下步骤:
步骤S1:请求端向API平台发送数据参数请求;
步骤S2:API平台根据请求生成带时间戳和随机字符串的密钥,并且,根据所述秘钥,对所述数据参数进行签名处理,并将秘钥和签名发送给请求端;
步骤S3:请求端访问所述API平台,API平台对所述访问进行拦截,并判断所述访问是否包含所述时间戳和随机字符串,否则则访问失败,是则进一步判断所述访问是否包含所述签名,是则进行步骤S4,否则则访问失败;
步骤S4:验证所述签名,验证成功则允许所述请求端访问所述参数对应的数据,验证不成功则访问失败。
2.根据权利要求1所述的开放API接口的签名验证方法,其特征在于:在所述步骤S2中,对所述数据参数进行签名处理具体包括:在原始的参数上拼接所述秘钥,并且,对拼接秘钥后的参数进行MD5加密。
3.根据权利要求2所述的开放API接口的签名验证方法,其特征在于:在所述步骤S3中,在判断所述访问是否包含所述签名后,还判断所述访问是否为超时访问,是则访问失败,否则进行步骤S4。
4.根据权利要求3所述的开放API接口的签名验证方法,其特征在于:在所述步骤S3中,在判断所述访问是否包含所述签名前,还判断所述访问是否包含请求端的访问令牌token;是则在判断所述访问不是为超时访问后,根据所述访问令牌token,确定所述请求端的用户唯一身份标识uid,否则访问失败。
5.根据权利要求4所述的开放API接口的签名验证方法,其特征在于:还根据所述用户唯一身份标识uid,确定所述请求端为合法请求端来源,当确定所述请求端不是为合法请求端来源时,则访问失败。
6.根据权利要求1-5任一所述的开放API接口的签名验证方法,其特征在于:访问失败失败后,还返回一错误码给所述请求端。
7.根据权利要求1-5任一所述的开放API接口的签名验证方法,其特征在于:步骤S4中,验证所述签名成功后,记录该次访问验证履历。
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210153455.1A CN114520724A (zh) | 2022-02-18 | 2022-02-18 | 一种开放api接口的签名验证方法 |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210153455.1A CN114520724A (zh) | 2022-02-18 | 2022-02-18 | 一种开放api接口的签名验证方法 |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114520724A true CN114520724A (zh) | 2022-05-20 |
Family
ID=81598396
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210153455.1A Pending CN114520724A (zh) | 2022-02-18 | 2022-02-18 | 一种开放api接口的签名验证方法 |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114520724A (zh) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116055043A (zh) * | 2023-02-06 | 2023-05-02 | 国家气象信息中心(中国气象局气象数据中心) | 一种数据服务接口鉴权方法及接口网关*** |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104935568A (zh) * | 2015-04-20 | 2015-09-23 | 成都康赛信息技术有限公司 | 一种面向云平台接口鉴权签名方法 |
CN107453878A (zh) * | 2017-08-11 | 2017-12-08 | 四川长虹电器股份有限公司 | 一种支持rest api防篡改防重放的方法 |
CN108183907A (zh) * | 2017-12-29 | 2018-06-19 | 浪潮通用软件有限公司 | 一种认证方法、服务器及认证*** |
CN110839004A (zh) * | 2018-08-16 | 2020-02-25 | 北京京东尚科信息技术有限公司 | 访问认证的方法和装置 |
CN112000951A (zh) * | 2020-08-31 | 2020-11-27 | 上海商汤智能科技有限公司 | 一种访问方法、装置、***、电子设备及存储介质 |
WO2021137769A1 (en) * | 2019-12-31 | 2021-07-08 | Envision Digital International Pte. Ltd. | Method and apparatus for sending and verifying request, and device thereof |
-
2022
- 2022-02-18 CN CN202210153455.1A patent/CN114520724A/zh active Pending
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104935568A (zh) * | 2015-04-20 | 2015-09-23 | 成都康赛信息技术有限公司 | 一种面向云平台接口鉴权签名方法 |
CN107453878A (zh) * | 2017-08-11 | 2017-12-08 | 四川长虹电器股份有限公司 | 一种支持rest api防篡改防重放的方法 |
CN108183907A (zh) * | 2017-12-29 | 2018-06-19 | 浪潮通用软件有限公司 | 一种认证方法、服务器及认证*** |
CN110839004A (zh) * | 2018-08-16 | 2020-02-25 | 北京京东尚科信息技术有限公司 | 访问认证的方法和装置 |
WO2021137769A1 (en) * | 2019-12-31 | 2021-07-08 | Envision Digital International Pte. Ltd. | Method and apparatus for sending and verifying request, and device thereof |
CN112000951A (zh) * | 2020-08-31 | 2020-11-27 | 上海商汤智能科技有限公司 | 一种访问方法、装置、***、电子设备及存储介质 |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116055043A (zh) * | 2023-02-06 | 2023-05-02 | 国家气象信息中心(中国气象局气象数据中心) | 一种数据服务接口鉴权方法及接口网关*** |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8478998B2 (en) | Authenticated communication using a shared unpredictable secret | |
KR100463736B1 (ko) | 보안 환경에서의 이동 통신 장치 소프트웨어의 디버깅 및테스팅 허가 방법 | |
RU2506637C2 (ru) | Способ и устройство верификации динамического пароля | |
CN111429254A (zh) | 一种业务数据处理方法、设备以及可读存储介质 | |
CN112671720B (zh) | 一种云平台资源访问控制的令牌构造方法、装置及设备 | |
CN106506494A (zh) | 一种开放平台的应用接入方法 | |
EP1673674A2 (en) | Maintaining privacy for transactions performable by a user device having a security module | |
CN112689285B (zh) | 一种移动端sdk的授权认证方法及*** | |
CN111800378A (zh) | 一种登录认证方法、装置、***和存储介质 | |
CN113395282A (zh) | 一种阻止第三方访问服务端资源的方法及*** | |
Guirat et al. | Formal verification of the W3C web authentication protocol | |
CN114520724A (zh) | 一种开放api接口的签名验证方法 | |
CN112272093B (zh) | 一种令牌管理的方法、电子设备及可读存储介质 | |
CN110611650B (zh) | 一种运行态pki/ca认证体系平滑升级方法 | |
CN111614458A (zh) | 网关jwt的生成方法、***及存储介质 | |
CN115021995B (zh) | 多渠道登录方法、装置、设备及存储介质 | |
CN115766192A (zh) | 基于ukey的离线安全认证方法、装置、设备及介质 | |
CN111723347B (zh) | 身份认证方法、装置、电子设备及存储介质 | |
CN112422292B (zh) | 一种网络安全防护方法、***、设备及存储介质 | |
CN109672526B (zh) | 一种管控可执行程序的方法及*** | |
CN114090996A (zh) | 多方***互信认证方法及装置 | |
CN114531246A (zh) | 数据下载方法及装置 | |
CN113591053A (zh) | 通用性的移动设备基于生物信息的识别方法及*** | |
CN112822007B (zh) | 一种用户认证方法、装置及设备 | |
CN113271306B (zh) | 数据请求、发送方法、设备以及*** |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |