当前位置: 首页 > news >正文

python 直播网站开发营销培训总结

python 直播网站开发,营销培训总结,进一步推进网站建设,网页设计尺寸厘米前言 在接口测试中,我们经常需要对请求进行签名,以保证数据的安全性。而SHA256withRSA是一种较为常见的签名算法,它可以使用私钥对数据进行签名,使用公钥进行验签。 但是,实现该算法签名可能会涉及到一些繁琐的操作&…

前言

在接口测试中,我们经常需要对请求进行签名,以保证数据的安全性。而SHA256withRSA是一种较为常见的签名算法,它可以使用私钥对数据进行签名,使用公钥进行验签。

但是,实现该算法签名可能会涉及到一些繁琐的操作,给我们的工作带来不小的困扰。

今天,我要向大家介绍一个神器——Postman,它可以轻松完成SHA256withRSA签名的实现,让您的API请求得到更加完善的保护。

接下来,我将简单介绍如何使用Postman实现SHA256withRSA签名,并且分享一些注意事项和技巧,希望能让大家轻松掌握这个技能。

获取pmlib

引入依赖bundle.js,有以下两种方式:
  1. 从github下载postman collection ,并导入进你的集合里
    官方使用介绍

 

  1. 将所需js所需js所需js全部复制保存成一个全局变量如:pmlib_code
    在这里插入图片描述
  2. 把自己的私钥设置成环境变量如:pri_key
    在这里插入图片描述

使用Pre-request Script对请求进行加签(具体加签字段请看自己项目) 

// 使用eval执行js
eval(pm.globals.get('pmlib_code'))// 生成rfctime
let date = new Date()
let y = date.getFullYear()
let m = date.getMonth()+1<10?'0'+(date.getMonth()+1):(date.getMonth()+1)
let d = date.getDate()<10?'0'+date.getDate():date.getDate()
let hh = date.getHours()<10?'0'+date.getHours():date.getHours();            
let mm = date.getMinutes()<10?'0'+date.getMinutes():date.getMinutes()
let ss = date.getSeconds()<10?'0'+date.getSeconds():date.getSeconds()
this.rfc_time = y +'-' + m + '-' + d + ' ' + hh + ':' + mm + ':' + ss
this.rfc_time = this.rfc_time.replace(/\s+/g, 'T')+'+08:00'
pm.variables.set('rfctime',this.rfc_time)
// console.log(pm.variables.get('rfctime'))const privkey = pm.environment.get('pri_key').replace(/\\n/g, "\n")// 随机字符串
const uuid = pm.variables.replaceIn('{{$randomUUID}}')
pm.variables.set('nonce_str', uuid)const requestBodyRaw = pm.variables.replaceIn(pm.request.body == undefined ? '' : pm.request.body.raw)const now = pm.variables.replaceIn('{{$timestamp}}')
pm.variables.set('req_time', now)
// 具体加密字段拼接请依据项目情况案例是:method+\n+url+\n+timestamp+\n+nonce_str+\n+body
var dataToSign = pm.request.method + "\n" +pm.request.url.getPathWithQuery() + "\n" +now + "\n" +uuid + "\n" +requestBodyRawconsole.log(dataToSign)const sha256withrsa = new pmlib.rs.KJUR.crypto.Signature({"alg": "SHA256withRSA"});
sha256withrsa.init(privkey);sha256withrsa.updateString(dataToSign);const sign = pmlib.rs.hextob64(sha256withrsa.sign());// console.log(sign);
pm.variables.set('sign', sign)
// 添加请求头
pm.request.headers.add({key:"Authorization",value:"SHA256-RSA nonce_str={{nonce_str}},timestamp={{req_time}},signature={{sign}}"
});

 使用Pre-request Script对请求进行加签(具体加签字段请看自己项目)

// 使用eval执行js
eval(pm.globals.get('pmlib_code'))// 生成rfctime
let date = new Date()
let y = date.getFullYear()
let m = date.getMonth()+1<10?'0'+(date.getMonth()+1):(date.getMonth()+1)
let d = date.getDate()<10?'0'+date.getDate():date.getDate()
let hh = date.getHours()<10?'0'+date.getHours():date.getHours();            
let mm = date.getMinutes()<10?'0'+date.getMinutes():date.getMinutes()
let ss = date.getSeconds()<10?'0'+date.getSeconds():date.getSeconds()
this.rfc_time = y +'-' + m + '-' + d + ' ' + hh + ':' + mm + ':' + ss
this.rfc_time = this.rfc_time.replace(/\s+/g, 'T')+'+08:00'
pm.variables.set('rfctime',this.rfc_time)
// console.log(pm.variables.get('rfctime'))const privkey = pm.environment.get('pri_key').replace(/\\n/g, "\n")// 随机字符串
const uuid = pm.variables.replaceIn('{{$randomUUID}}')
pm.variables.set('nonce_str', uuid)const requestBodyRaw = pm.variables.replaceIn(pm.request.body == undefined ? '' : pm.request.body.raw)const now = pm.variables.replaceIn('{{$timestamp}}')
pm.variables.set('req_time', now)
// 具体加密字段拼接请依据项目情况案例是:method+\n+url+\n+timestamp+\n+nonce_str+\n+body
var dataToSign = pm.request.method + "\n" +pm.request.url.getPathWithQuery() + "\n" +now + "\n" +uuid + "\n" +requestBodyRawconsole.log(dataToSign)const sha256withrsa = new pmlib.rs.KJUR.crypto.Signature({"alg": "SHA256withRSA"});
sha256withrsa.init(privkey);sha256withrsa.updateString(dataToSign);const sign = pmlib.rs.hextob64(sha256withrsa.sign());// console.log(sign);
pm.variables.set('sign', sign)
// 添加请求头
pm.request.headers.add({key:"Authorization",value:"SHA256-RSA nonce_str={{nonce_str}},timestamp={{req_time}},signature={{sign}}"
});

至此SHA256withRSA签名已完成
在这里插入图片描述

 感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:

 

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!有需要的小伙伴可以点击下方小卡片领取 

 

http://www.hkea.cn/news/305726/

相关文章:

  • 小型企业网站系统cilimao磁力猫最新版地址
  • 铁岭网站建设移动网站广东网站seo
  • 网站模板插件sem和seo
  • 用wordpress制作网站模板沈阳seo
  • 优化一个网站多少钱宜昌网站seo
  • 刚做的网站怎么才能搜索到枸橼酸西地那非片功效效及作用
  • 罗湖区网站公司专业模板建站
  • 哪有备案好的网站国产系统2345
  • 网站开发怎么让别人看到最新营销模式有哪些
  • ssm网站开发源码百度推广多少钱一个月
  • 手游门户网站建设appstore关键词优化
  • 齐河网站开发seo服务内容
  • 北京微信网站建设费用想卖产品怎么推广宣传
  • 网站上线的步骤厦门网站推广公司哪家好
  • 网站做app的软件有哪些百度一下你就知道下载
  • 界面设计的重要性百度seo关键词排名推荐
  • 股票做T网站直播营销
  • 北京手机网站建设公司排名技术优化seo
  • wordpress可爱的主题seo优化教程
  • 自己可以申请网站做外卖吗网站描述和关键词怎么写
  • 公司网站网页设计seo站长工具推广平台
  • 重庆南岸营销型网站建设公司哪家专业真实的网站制作
  • 郑州企业网站建设兼职推广渠道
  • 网站哪些数据优化大师的作用
  • 政府网站集约化建设总结营销软文推广平台
  • 学网站开发跟那个专业最相近百度站长平台注册
  • 网站开发python电脑培训班有哪些科目
  • 惠州响应式网站哪家好云盘搜索
  • spring做网站合肥seo排名收费
  • 做58网站怎么赚钱二十个优化