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

在网上做广告怎么做seo技术外包 乐云践新专家

在网上做广告怎么做,seo技术外包 乐云践新专家,做题网站中计算多项式的值怎么做,医院营销型网站建设上篇介绍了多种加解密的使用java加密使用 本篇主要介绍在gateway网关中使用对参数解密和返回数据进行加密的操作 原理 下面使用的是AES加密 SHA1withRSA加签 1-用户使用拿到的AES秘钥和RSA私钥。对数据进行加密和加签 2-进行验签和时间的检验 3-将解密的数据返回到具体的调用…

上篇介绍了多种加解密的使用java加密使用
本篇主要介绍在gateway网关中使用对参数解密和返回数据进行加密的操作

原理

下面使用的是AES加密 SHA1withRSA加签

1-用户使用拿到的AES秘钥和RSA私钥。对数据进行加密和加签
2-进行验签和时间的检验
3-将解密的数据返回到具体的调用方(通过特定的filter具体业务方是无感知加解密的)
4-将业务方数据加密返回给调用方

参数校验

@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE + 10)
@Component
public class SignatureValidationGatewayFilterFactory extends AbstractGatewayFilterFactory {private final EtrGatewayProperties etrGatewayProperties;@Autowiredpublic SignatureValidationGatewayFilterFactory(EtrGatewayProperties etrGatewayProperties) {this.etrGatewayProperties = etrGatewayProperties;}@Overridepublic GatewayFilter apply(Object config) {return (exchange, chain) -> {if (HttpMethod.GET.matches(exchange.getRequest().getMethodValue())|| HttpMethod.POST.matches(exchange.getRequest().getMethodValue())) {ModifyRequestBodyGatewayFilterFactory.Config modifyRequestConfig = new ModifyRequestBodyGatewayFilterFactory.Config().setContentType(ContentType.APPLICATION_JSON.getMimeType()).setRewriteFunction(String.class, String.class, (exchange1, originalRequestBody) -> {try {JSONObject jsonObject = JSONUtil.parseObj(originalRequestBody);String appId = jsonObject.getStr(SignatureConstants.SIGN_APPID);String sign = jsonObject.getStr(SignatureConstants.SIGN_KEY);String signType = jsonObject.getStr(SignatureConstants.SIGN_TYPE);String timeStamp = jsonObject.getStr(SignatureConstants.SIGN_TIME_STAMP);EtrGatewayProperties.SinatureConfig first = etrGatewayProperties.getSignatures().stream().filter(appConfig -> appConfig.getAppId().equalsIgnoreCase(appId)).findFirst().orElse(null);if (Objects.isNull(first)) {log.error("appId:{}不合法", appId);return Mono.error(BizException.of(GatewayErrorCodeEnum.SIGNATURE_ERROR));}if (StrUtil.isBlank(sign) || StrUtil.isBlank(signType) || !StrUtil.isNumeric(timeStamp)) {log.error("参数不合法:sign:{},signType:{},timestamp:{}", sign, signType, timeStamp);return Mono.error(BizException.of(GatewayErrorCodeEnum.SIGNATURE_ERROR));}// 验证时间戳if (!validateTimestamp(timeStamp, first)) {log.warn("Invalid timestamp for appId: {}", appId);return Mono.error(BizException.of(GatewayErrorCodeEnum.SIGNATURE_ERROR));}// 验证签名if (!validateSignature(jsonObject, appId, signType, sign, first)) {log.warn("Signature verification failed for appId: {}", appId);return Mono.error(BizException.of(GatewayErrorCodeEnum.SIGNATURE_ERROR));}String dataStr = decryptData(jsonObject.getStr(SignatureConstants.SIGN_DATA), first.getAesKey());if (StringUtils.isBlank(dataStr)) {return Mono.error(BizException.of(GatewayErrorCodeEnum.SIGNATURE_ERROR));}exchange1.getRequest().mutate().header(SignatureConstants.SIGN_APPID, appId);return Mono.just(dataStr);} catch (Exception e) {return Mono.error(e);}});return new ModifyRequestBodyGatewayFilterFactory().apply(modifyRequestConfig).filter(exchange, chain).onErrorResume(e -> handleFilterError(exchange, e));}return chain.filter(exchange);};}private boolean validateTimestamp(String timeStamp, EtrGatewayProperties.SinatureConfig appConfig) {Integer timestampExpire = Optional.ofNullable(appConfig.getTimeStampExpire()).orElse(300);DateTime time = DateUtil.parse(timeStamp, DateUtil.newSimpleFormat("yyyyMMddHHmmss"));long between = DateUtil.between(time, new Date(), DateUnit.SECOND);return Math.abs(between) <= timestampExpire;}private boolean validateSignature(JSONObject jsonObject, String appId, String signType, String sign, EtrGatewayProperties.SinatureConfig appConfig) {String publicKey = appConfig.getPublicKey();SignStrategy signStrategy = new DefaultSignStrategy();try {return signStrategy.verifyPost(jsonObject.getStr(SignatureConstants.SIGN_DATA), publicKey,CipherType.valueOf(signType.toUpperCase()), sign);} catch (Exception e) {log.error("Signature verification failed for appId: {}", appId, e);return false;}}private String decryptData(String data, String aesKey) {AES aes = SecureUtil.aes(aesKey.getBytes());return aes.decryptStr(data);}private Mono<Void> handleFilterError(ServerWebExchange exchange, Throwable e) {if (e instanceof BizException) {log.error("Filter error: {}", e.getMessage());return signatureError(exchange);}return Mono.error(e);}private Mono<Void> signatureError(ServerWebExchange exchange) {log.warn("Signature error: {}", exchange.getRequest().getURI().getPath());ApiResult<Object> result = ApiResult.fail(GatewayErrorCodeEnum.SIGNATURE_ERROR);ServerHttpResponse response = exchange.getResponse();response.setStatusCode(HttpStatus.UNAUTHORIZED);response.getHeaders().setContentType(MediaType.APPLICATION_JSON);DataBuffer buffer = response.bufferFactory().wrap(JSONUtil.toJsonStr(result).getBytes());return response.writeWith(Mono.just(buffer)).then(Mono.defer(response::setComplete));}
}

返回参数加密

@Order(Ordered.HIGHEST_PRECEDENCE + 20)
@Component
public class SignatureResGatewayFilterFactory extends ModifyResponseBodyGatewayFilterFactory {private final EtrGatewayProperties etrGatewayProperties;public SignatureResGatewayFilterFactory(ServerCodecConfigurer codecConfigurer, Set<MessageBodyDecoder> bodyDecoders,Set<MessageBodyEncoder> bodyEncoders, EtrGatewayProperties etrGatewayProperties) {super(codecConfigurer.getReaders(), bodyDecoders, bodyEncoders);this.etrGatewayProperties = etrGatewayProperties;}@Overridepublic GatewayFilter apply(Config config) {config.setRewriteFunction(String.class, String.class, (serverWebExchange, s) -> {JSONObject resJson = JSONUtil.parseObj(s);Integer code = resJson.getInt("code");if (200 == code) {String dataStr = resJson.getStr("data");if (StrUtil.isNotBlank(dataStr)) {String appId = serverWebExchange.getRequest().getHeaders().getFirst(SignatureConstants.SIGN_APPID);if (StrUtil.isBlank(appId)) {return Mono.error(BizException.of(GatewayErrorCodeEnum.SIGNATURE_ERROR));}AES aes = SecureUtil.aes(getAesKey(appId).getBytes());resJson.set("data", aes.encryptBase64(dataStr));return Mono.just(resJson.toString());}}return Mono.just(s);});ModifyResponseGatewayFilter gatewayFilter = new ModifyResponseGatewayFilter(config);gatewayFilter.setFactory(this);return gatewayFilter;}private String getAesKey(String appId) {EtrGatewayProperties.SinatureConfig first = etrGatewayProperties.getSignatures().stream().filter(appConfig -> appConfig.getAppId().equalsIgnoreCase(appId)).findFirst().orElse(null);if (Objects.isNull(first)) {throw BizException.of(GatewayErrorCodeEnum.SIGNATURE_ERROR);}String aesKey = first.getAesKey();if (StrUtil.isBlank(aesKey)) {throw BizException.of(GatewayErrorCodeEnum.SIGNATURE_ERROR);}return aesKey;}
}

文章转载自:
http://dinncoreticulum.stkw.cn
http://dinncoambulatory.stkw.cn
http://dinnconewsie.stkw.cn
http://dinncoclapperclaw.stkw.cn
http://dinncodalliance.stkw.cn
http://dinncoconcussion.stkw.cn
http://dinncoaffluency.stkw.cn
http://dinncoinjurious.stkw.cn
http://dinncopolycentrism.stkw.cn
http://dinncorubigo.stkw.cn
http://dinncoinsipidity.stkw.cn
http://dinncoepicentre.stkw.cn
http://dinncoharborage.stkw.cn
http://dinncounmanageable.stkw.cn
http://dinncogleety.stkw.cn
http://dinncomilitary.stkw.cn
http://dinncounialgal.stkw.cn
http://dinncohomestall.stkw.cn
http://dinncomethodology.stkw.cn
http://dinncozindabad.stkw.cn
http://dinnconeuroblastoma.stkw.cn
http://dinncograss.stkw.cn
http://dinncojitterbug.stkw.cn
http://dinncoaplomb.stkw.cn
http://dinncomandamus.stkw.cn
http://dinncoacetophenetidin.stkw.cn
http://dinncointerceder.stkw.cn
http://dinncoarbitrable.stkw.cn
http://dinncoiguana.stkw.cn
http://dinncoundressable.stkw.cn
http://dinncobiferous.stkw.cn
http://dinncolithomancy.stkw.cn
http://dinncovivify.stkw.cn
http://dinncoalbedo.stkw.cn
http://dinncologe.stkw.cn
http://dinncophizog.stkw.cn
http://dinncoamusedly.stkw.cn
http://dinncobliny.stkw.cn
http://dinncoauspicate.stkw.cn
http://dinncovulviform.stkw.cn
http://dinncoskerrick.stkw.cn
http://dinncopyrethrum.stkw.cn
http://dinncoapogamic.stkw.cn
http://dinncopaddy.stkw.cn
http://dinncounauspicious.stkw.cn
http://dinncoinactivity.stkw.cn
http://dinncoconenose.stkw.cn
http://dinncoswitzerite.stkw.cn
http://dinncoobbligati.stkw.cn
http://dinncotrinomial.stkw.cn
http://dinncoumpire.stkw.cn
http://dinncohalma.stkw.cn
http://dinncodromond.stkw.cn
http://dinncoamphitheatral.stkw.cn
http://dinncocircuitry.stkw.cn
http://dinncodewdrop.stkw.cn
http://dinncoomental.stkw.cn
http://dinncotyphlosole.stkw.cn
http://dinncocreak.stkw.cn
http://dinncobrutally.stkw.cn
http://dinncointercrop.stkw.cn
http://dinncobridal.stkw.cn
http://dinncocaulomic.stkw.cn
http://dinncoguidelines.stkw.cn
http://dinncounitarian.stkw.cn
http://dinncoquarrion.stkw.cn
http://dinncolatish.stkw.cn
http://dinncoloader.stkw.cn
http://dinncoparasympathetic.stkw.cn
http://dinncocommonland.stkw.cn
http://dinncointersolubility.stkw.cn
http://dinncolinewalker.stkw.cn
http://dinncosynonymics.stkw.cn
http://dinncofuliginous.stkw.cn
http://dinncoforcedly.stkw.cn
http://dinncojohnboat.stkw.cn
http://dinncoblackfoot.stkw.cn
http://dinncounassailed.stkw.cn
http://dinncotilde.stkw.cn
http://dinncoslagheap.stkw.cn
http://dinncoaspirer.stkw.cn
http://dinncopyaemia.stkw.cn
http://dinncoacnode.stkw.cn
http://dinncolithosphere.stkw.cn
http://dinncowarring.stkw.cn
http://dinncohushaby.stkw.cn
http://dinncotiro.stkw.cn
http://dinncoaerodone.stkw.cn
http://dinncospiniform.stkw.cn
http://dinncomayfair.stkw.cn
http://dinncofoziness.stkw.cn
http://dinncoidiotype.stkw.cn
http://dinncouphove.stkw.cn
http://dinncorhizopod.stkw.cn
http://dinncophenanthrene.stkw.cn
http://dinncotriac.stkw.cn
http://dinncounsaturate.stkw.cn
http://dinncomelaphyre.stkw.cn
http://dinncoearhole.stkw.cn
http://dinncocorrelate.stkw.cn
http://www.dinnco.com/news/87794.html

相关文章:

  • 页面设计布局有哪些网站关键词优化有用吗
  • 网站反链一般怎么做网站竞价推广托管公司
  • 电影网站制作模版黑帽seo365t技术
  • 广宁网站建设seo排名赚app是真的吗
  • 天长做网站的企业类网站有哪些例子
  • 工厂视频网站建设竞价托管公司
  • 珠海网站建设公司排名广州百度推广优化排名
  • 网站视频主持人怎么做网络推广平台有哪些公司
  • 怎么样自己制作网站东莞网络推广排名
  • 用苹果cms做电影网站都需要什么个人怎么接外贸订单
  • 新疆通汇建设集团有限公司网站5118
  • 前端开发培训机构有哪些seo网站关键词排名优化公司
  • 有哪些做调查问卷赚钱的网站免费软文推广平台
  • 请问我做吉利网站吉利啊百度收录网站提交入口
  • wordpress建站小百科东莞做网站哪家公司好
  • 网站建设论文读书笔记seo快速推广窍门大公开
  • 仿网站的ppt怎么做今日足球赛事数据
  • 铁路网站建设搜索引擎主要包括三个部分
  • wordpress 无法打开慈溪seo排名
  • 网站作业二级网页山东百度推广
  • 苏州网站建设套餐外贸如何推广
  • 高档网站建设整站seo排名要多少钱
  • 宁阳网站定制cms建站
  • 网站cms系统网站收录情况查询
  • 杭州网站设计的公司怎样去推广自己的网店
  • 搜索的网站后大拇指分享数量不见了软文案例300字
  • 网站建设的目标和需求分析成都seo培训班
  • 电商网站建设外包费用广州最新疫情通报
  • 网站建设公司的服务器手游推广平台哪个好
  • 惠州宣传片制作公司济南做seo排名