潞城网站建设公司seo网络优化师招聘

pingmian/2025/10/14 7:44:34/文章来源:
潞城网站建设公司,seo网络优化师招聘,蜜芽加密通道入口2021,wordpress 手机端异常Google身份验证器Google Authenticator是谷歌推出的一款基于时间与哈希的一次性密码算法的两步验证软件令牌#xff0c;此软件用于Google的认证服务。此项服务所使用的算法已列于RFC 6238和RFC 4226中。谷歌验证器上的动态密码按照时间或使用次数不断动态变化#xff08;默认…Google身份验证器Google Authenticator是谷歌推出的一款基于时间与哈希的一次性密码算法的两步验证软件令牌此软件用于Google的认证服务。此项服务所使用的算法已列于RFC 6238和RFC 4226中。谷歌验证器上的动态密码按照时间或使用次数不断动态变化默认30秒变更一次。 在本实现demo中注释说明非常详尽可供参考如遇问题欢迎可以留言沟通。 废话不多说直接上代码本次代码尽可能简单最简单的结构附图 package com.wuge.google;import org.apache.commons.codec.binary.Base32; import org.apache.commons.codec.binary.Hex; import org.springframework.util.StringUtils;import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom;/*** 谷歌身份验证器工具类** author wuge*/ public class GoogleAuthenticator {/*** 时间前后偏移量* 用于防止客户端时间不精确导致生成的TOTP与服务器端的TOTP一直不一致* 如果为0,当前时间为 10:10:15* 则表明在 10:10:00-10:10:30 之间生成的TOTP 能校验通过* 如果为1,则表明在* 10:09:30-10:10:00* 10:10:00-10:10:30* 10:10:30-10:11:00 之间生成的TOTP 能校验通过* 以此类推*/private static int WINDOW_SIZE 0;/*** 加密方式HmacSHA1、HmacSHA256、HmacSHA512*/private static final String CRYPTO HmacSHA1;/*** 生成密钥每个用户独享一份密钥** return*/public static String getSecretKey() {SecureRandom random new SecureRandom();byte[] bytes new byte[20];random.nextBytes(bytes);Base32 base32 new Base32();String secretKey base32.encodeToString(bytes);// make the secret key more human-readable by lower-casing and// inserting spaces between each group of 4 charactersreturn secretKey.toUpperCase();}/*** 生成二维码内容** param secretKey 密钥* param account 账户名* param issuer 网站地址可不写* return*/public static String getQrCodeText(String secretKey, String account, String issuer) {String normalizedBase32Key secretKey.replace( , ).toUpperCase();try {return otpauth://totp/ URLEncoder.encode((!StringUtils.isEmpty(issuer) ? (issuer :) : ) account, UTF-8).replace(, %20) ?secret URLEncoder.encode(normalizedBase32Key, UTF-8).replace(, %20) (!StringUtils.isEmpty(issuer) ? (issuer URLEncoder.encode(issuer, UTF-8).replace(, %20)) : );} catch (UnsupportedEncodingException e) {throw new IllegalStateException(e);}}/*** 获取验证码** param secretKey* return*/public static String getCode(String secretKey) {String normalizedBase32Key secretKey.replace( , ).toUpperCase();Base32 base32 new Base32();byte[] bytes base32.decode(normalizedBase32Key);String hexKey Hex.encodeHexString(bytes);long time (System.currentTimeMillis() / 1000) / 30;String hexTime Long.toHexString(time);return TOTP.generateTOTP(hexKey, hexTime, 6, CRYPTO);}/*** 检验 code 是否正确** param secret 密钥* param code code* param time 时间戳* return*/public static boolean checkCode(String secret, long code, long time) {Base32 codec new Base32();byte[] decodedKey codec.decode(secret);// convert unix msec time into a 30 second window// this is per the TOTP spec (see the RFC for details)long t (time / 1000L) / 30L;// Window is used to check codes generated in the near past.// You can use this value to tune how far youre willing to go.long hash;for (int i -WINDOW_SIZE; i WINDOW_SIZE; i) {try {hash verifyCode(decodedKey, t i);} catch (Exception e) {// Yes, this is bad form - but// the exceptions thrown would be rare and a static// configuration problem// e.printStackTrace();throw new RuntimeException(e.getMessage());}if (hash code) {return true;}}return false;}/*** 根据时间偏移量计算** param key* param t* return* throws NoSuchAlgorithmException* throws InvalidKeyException*/private static long verifyCode(byte[] key, long t) throws NoSuchAlgorithmException, InvalidKeyException {byte[] data new byte[8];long value t;for (int i 8; i-- 0; value 8) {data[i] (byte) value;}SecretKeySpec signKey new SecretKeySpec(key, CRYPTO);Mac mac Mac.getInstance(CRYPTO);mac.init(signKey);byte[] hash mac.doFinal(data);int offset hash[20 - 1] 0xF;// Were using a long because Java hasnt got unsigned int.long truncatedHash 0;for (int i 0; i 4; i) {truncatedHash 8;// We are dealing with signed bytes:// we just keep the first byte.truncatedHash | (hash[offset i] 0xFF);}truncatedHash 0x7FFFFFFF;truncatedHash % 1000000;return truncatedHash;}public static void main(String[] args) {for (int i 0; i 100; i) {String secretKey getSecretKey();System.out.println(secretKey secretKey);String code getCode(secretKey);System.out.println(code code);boolean b checkCode(secretKey, Long.parseLong(code), System.currentTimeMillis());System.out.println(isSuccess b);}} }package com.wuge.google;import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import java.lang.reflect.UndeclaredThrowableException; import java.math.BigInteger; import java.security.GeneralSecurityException;/*** 验证码生成工具类** author wuge*/ public class TOTP {private static final int[] DIGITS_POWER {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000};/*** This method uses the JCE to provide the crypto algorithm. HMAC computes a* Hashed Message Authentication Code with the crypto hash algorithm as a* parameter.** param crypto : the crypto algorithm (HmacSHA1, HmacSHA256, HmacSHA512)* param keyBytes : the bytes to use for the HMAC key* param text : the message or text to be authenticated*/private static byte[] hmac_sha(String crypto, byte[] keyBytes, byte[] text) {try {Mac hmac;hmac Mac.getInstance(crypto);SecretKeySpec macKey new SecretKeySpec(keyBytes, RAW);hmac.init(macKey);return hmac.doFinal(text);} catch (GeneralSecurityException gse) {throw new UndeclaredThrowableException(gse);}}/*** This method converts a HEX string to Byte[]** param hex : the HEX string* return: a byte array*/private static byte[] hexStr2Bytes(String hex) {// Adding one byte to get the right conversion// Values starting with 0 can be convertedbyte[] bArray new BigInteger(10 hex, 16).toByteArray();// Copy all the REAL bytes, not the firstbyte[] ret new byte[bArray.length - 1];System.arraycopy(bArray, 1, ret, 0, ret.length);return ret;}/*** This method generates a TOTP value for the given set of parameters.** param key : the shared secret, HEX encoded* param time : a value that reflects a time* param returnDigits : number of digits to return* param crypto : the crypto function to use* return: a numeric String in base 10 that includes*/public static String generateTOTP(String key, String time, String returnDigits, String crypto) {int codeDigits Integer.decode(returnDigits);String result null;// Using the counter// First 8 bytes are for the movingFactor// Compliant with base RFC 4226 (HOTP)while (time.length() 16) {time 0 time;}// Get the HEX in a Byte[]byte[] msg hexStr2Bytes(time);byte[] k hexStr2Bytes(key);byte[] hash hmac_sha(crypto, k, msg);// put selected bytes into result intint offset hash[hash.length - 1] 0xf;int binary ((hash[offset] 0x7f) 24)| ((hash[offset 1] 0xff) 16)| ((hash[offset 2] 0xff) 8) | (hash[offset 3] 0xff);int otp binary % DIGITS_POWER[codeDigits];result Integer.toString(otp);while (result.length() codeDigits) {result 0 result;}return result;} }package com.wuge;import com.wuge.google.GoogleAuthenticator; import org.iherus.codegen.qrcode.SimpleQrcodeGenerator; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpServletResponse;/*** 项目启动类** author wuge*/ RestController SpringBootApplication public class Application {private static String SECRET_KEY ;public static void main(String[] args) {SpringApplication.run(Application.class, args);}/*** 生成 Google 密钥两种方式任选一种*/GetMapping(getSecretKey)public String getSecretKey() {String secretKey GoogleAuthenticator.getSecretKey();SECRET_KEY secretKey;return secretKey;}/*** 生成二维码APP直接扫描绑定两种方式任选一种*/GetMapping(getQrcode)public void getQrcode(RequestParam(name) String name, HttpServletResponse response) throws Exception {String secretKey GoogleAuthenticator.getSecretKey();SECRET_KEY secretKey;// 生成二维码内容String qrCodeText GoogleAuthenticator.getQrCodeText(secretKey, name, );// 生成二维码输出new SimpleQrcodeGenerator().generate(qrCodeText).toStream(response.getOutputStream());}/*** 获取code*/GetMapping(getCode)public String getCode() {return GoogleAuthenticator.getCode(SECRET_KEY);}/*** 验证 code 是否正确*/GetMapping(checkCode)public Boolean checkCode(RequestParam(code) String code) {return GoogleAuthenticator.checkCode(SECRET_KEY, Long.parseLong(code), System.currentTimeMillis());} }?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.3.1.RELEASE/versionrelativePath//parentrepositories!-- 指定仓库地址提升速度 --repositoryidaliyun/idnamealiyun Repository/nameurlhttp://maven.aliyun.com/nexus/content/groups/public/urlsnapshotsenabledfalse/enabled/snapshots/repository/repositoriesgroupIdcom.asurplus/groupIdartifactIdasurplus/artifactIdversion0.0.1-SNAPSHOT/versionnameasurplus/namedescriptionGoogle身份验证器/descriptionpropertiesproject.reporting.outputEncodingUTF-8/project.reporting.outputEncodingproject.build.sourceEncodingUTF-8/project.build.sourceEncodingjava.version1.8/java.versioncodec.version1.15/codec.versionqrext4j.version1.3.1/qrext4j.version/propertiesdependencies!-- web支持 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency!-- 加密工具 --!--密钥生成--dependencygroupIdcommons-codec/groupIdartifactIdcommons-codec/artifactIdversion${codec.version}/version/dependency!-- 二维码依赖 --dependencygroupIdorg.iherus/groupIdartifactIdqrext4j/artifactIdversion${qrext4j.version}/version/dependency/dependenciesbuildfinalNamegoogle-auth/finalNamepluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins/build/project

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/88021.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

北京朝阳做网站wordpress 中文插件下载

需求描述对于数据分析人员来说,工作的基础是数据,没有数据分析就无从谈起,即巧妇难为无米之炊。#数据库# #数据迁移# #Oracle# 然而,数据分析往往在实验环境或者准生产环境中开展,而数据分布在生产环境,因此…

seo网站优化知识安阳做一个网站多少钱

深度学习包含深度迁移学习,它们都利用了深层神经网络(Deep Neural Network,DNN)来处理数据,并从中学习特征。但是,它们也有一些区别。 深度学习是一种机器学习方法,它通过多层神经网络来自动学…

制作网站制作网站建设的如何把网站能搜到

键盘和鼠标是与计算机交互的重要外围设备。有些人可能会争辩说,你只需要这些设备中的一个,但事实上,只使用其中一个设备的电脑可能非常困难。但是,如果你的鼠标或笔记本电脑的触控板突然停止工作,而你无法修复它或无法使用备用鼠标,该怎么办? 在这种情况下,你可以使用…

隆昌市住房和城乡建设厅网站网站设计是用ps做图吗

原文链接: go-zero 的自适应熔断器 上篇文章我们介绍了微服务的限流,详细分析了计数器限流和令牌桶限流算法,这篇文章来说说熔断。 熔断和限流还不太一样,限流是控制请求速率,只要还能承受,那么都会处理&…

dw怎么做网站珠海网站建设方案开发

(请先看置顶博文)本博打开方式,请详读_liO_Oil的博客-CSDN博客_怎么把androidstudio卸载干净 题目大意:王老师爬楼梯,他可以每次走1级或者2级,输入楼梯的级数,求不同的走法数。例如:…

北京最大做网站的公司万全孔家庄做网站

深度剖析:六大虚拟DOM库的奥秘与应用场景 前言 虚拟DOM(Document Object Model)是用于表示和操作HTML文档的抽象数据结构。虚拟DOM库是构建用户界面的重要工具,它们提供了高效的更新机制、组件化开发等功能,使开发者…

福田设计网站华为手机软文范文300

大家好,我是等天黑。相信很多朋友应该注意到了,我最近发了很多系统设计的文章。是的,到目前为止,已经发了有 7 篇文章。这些内容主要翻译自 Alex Xu 的 《System Design Interview》,有卷一和卷二两本。System Design …

群晖nas做网站网站空间是先备案后买

智能优化算法应用:基于人工蜂群算法3D无线传感器网络(WSN)覆盖优化 - 附代码 文章目录 智能优化算法应用:基于人工蜂群算法3D无线传感器网络(WSN)覆盖优化 - 附代码1.无线传感网络节点模型2.覆盖数学模型及分析3.人工蜂群算法4.实验参数设定5.算法结果6.…

网站建设实验心得用.net做网站好 还是用php

匹配模式 每个目标都有个叫<Target_Name>DAGToDAGISel的SelectionDAGISel子类.它通过实现子类的Select方法来选指. 如SPARC中的SparcDAGToDAGISel::Select()(见lib/Target/Sparc/SparcISelDAGToDAG.cpp文件).接收要匹配的SDNode参数,返回代表物理指令的SDNode值;否则出…

临河网站建设视觉设计和ui设计有什么区别

在VBA编辑器中&#xff0c;你可以创建、编辑和运行VBA宏代码&#xff0c;以实现自动化任务和自定义Word 功能。如果你是VBA编程初学者&#xff0c;可以在VBA编辑器中查看Word VBA宏代码示例&#xff0c;以便更好地了解如何使用VBA编写代码。 要打开VBA编辑器&#xff0c;你可以…

宽屏大气企业网站源码嘉兴网站建设seo

2024最新同城上门预约家政按摩源码简介&#xff1a; 开源无需授权2024最新同城上门预约家政按摩小程序&#xff0b;公众号H5&#xff0b;APP源码系统下载&#xff0c;前端采用uni-app开发&#xff0c; 后端thinkphp框架开发。适配多端&#xff08;小程序&#xff0b;公众号H5&…

phython 做的网站济南网站建设哪家便宜

在现在这个繁荣的游戏开发行业中&#xff0c;选择合适的游戏引擎是非常重要的。其中&#xff0c;Unreal Engine作为一款功能强大的游戏引擎&#xff0c;在业界广受赞誉。那Unreal Engine游戏引擎究竟有哪些优势&#xff0c;带大家简单的了解一下。 图形渲染技术 Unreal Engin…

教育考试类网站建设电子商务及网站建设

1,使用数组方法: 1) 数字转字符串,字符串按照小数点.分割 2) 整数部分拆分成字符串数组,并倒叙 3) 遍历, 按照每三位添加逗号,号 4) 拼接整数部分小数部分 function format_width_array(number) { // 将数字转换为千分位字符串const arr String(number).split(.);// 整数…

建网站什么样的域名最好外包网站建设价格

Class/Interface增强允许增加&#xff0c; 对已有的方法增加可选参数 添加方法&#xff0c;事件&#xff0c;事件处理 参考接口 对存在的方法添加出口&#xff0c;其中包括方法开始前的出口&#xff08;Pre-Exit&#xff09;&#xff0c;方法结束快结束的出口(Post-Exit)&#…

新建免费网站万能应用商店下载安装

浅谈爬虫 《一》 python ‘’正文之前先啰嗦一下&#xff0c;准确来说&#xff0c;在下还只是一个刚入门IT世界的菜鸟&#xff0c;工作近两年了&#xff0c;之前做前端的时候就想写博客来着&#xff0c;现在都转做python了&#xff0c;如果还不开始写点什么&#xff0c;估计时间…

承德网站制作与建设宁波网站建设哪里便宜

爬虫的一些工具(二) 1. 常有的工具 (1). python(2). pycharm(3).浏览器i.chromeii.火狐(4).fiddler的使用2 fiddler的使用 (1).操作界面(2)界面含义请求(Request)部分详解名称含义Headers显示客户端发送到服务器的 HTTP 请求的,header 显示为一个分级视图&#xff0c;包含了 We…

阿里云服务器可以做彩票网站吗wordpress文章评论插件

一、效果图 二、会用到的知识 目录结构与URL路由注册request与response对象模板基础与模板继承ORM查询后台管理 三、实现步骤 1. terminal 输入 django-admin startapp the_10回车 2. 注册&#xff0c; 在 tutorial子文件夹settings.py INSTALLED_APPS 中括号添加 "the…

4秒网站建设上海到北京高铁多少钱

目录 第一章、技术栈1.0&#xff09;集合框架等基础1、arraylist &#xff0c;linkedlist的区别&#xff0c;为啥集合有的快有的慢2、字符串倒叙输出3、讲一下Java的集合框架4、定义一下线程安全的map&#xff0c;有哪些方法5、equals比较问题6、hashtable和hashmap的区别7、8、…

新网站怎么做seo优化如何做一个自己的电商平台

【 摘自昆山论坛网友&#xff1a;苏格拉底的苏 】 落户共用了一个月左右时间&#xff1a; 从10月30号开始&#xff0c;今天11月28号结束。 整整30天&#xff0c;人才引进落户之路终于走完。 速度还是挺快的&#xff0c;其中审核时间花了27天&#xff0c;从11月25日收到复审通过…