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

比尤果网做的好的网站宜昌今日头条新闻

比尤果网做的好的网站,宜昌今日头条新闻,网站头尾一样的怎么做最好,哈尔滨百姓网最近才知道公司还在做国外的业务,要实现一个登陆辅助验证系统。咱们国内是用手机短信做验证,当然 这个google身份验证只是一个辅助验证登陆方式。看一下演示 看到了嘛。 手机下载一个谷歌身份验证器就可以 。 谷歌身份验证器,我本身是一个基…

最近才知道公司还在做国外的业务,要实现一个登陆辅助验证系统。咱们国内是用手机短信做验证,当然 这个google身份验证只是一个辅助验证登陆方式。看一下演示

 

看到了嘛。 手机下载一个谷歌身份验证器就可以 。

谷歌身份验证器,我本身是一个基于时间做加密计算然后得出相同结果 本身很简单。

下边在网上查的 可以做一下了解:谷歌身份验证就是基于TOTP算法

TOTP算法,全称为“Time-based One-time Password algorithm”,中文译为基于时间的一次性密码算法。它是一种从共享密钥和当前时间计算一次性密码的算法,已被采纳为Internet工程任务组标准RFC 6238。TOTP是开放身份验证计划(OATH)的基石,并被用于许多双因素身份验证系统。详细的可以百度一下搜索原理,我们这里只是介绍一下使用。

下边是代码 :

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;public class GoogleAuthenticator {/*** 时间前后偏移量 目的解决30秒内有计算有误差不一致的发生*/private static int WINDOW_SIZE = 0;/*** 加密方式,HmacSHA1、HmacSHA256、HmacSHA512*/private static final String CRYPTO = "HmacSHA1";/*** 生成二维码内容** @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);}}/*** 检验 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 you're willing to go.long hash;for (int i = -WINDOW_SIZE; i <= WINDOW_SIZE; ++i) {try {hash = verifyCode(decodedKey, t + i);} catch (Exception e) {return false;}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;// We're using a long because Java hasn't 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 String getkeyBase32() {// 生成一个随机的密钥字节数组SecureRandom random = new SecureRandom();byte[] keyBytes = new byte[20]; // 一般长度为16、20或32字节random.nextBytes(keyBytes);// 将密钥转换成Base32格式以便用户显示或扫描二维码Base32 base32 = new Base32();String secretKeyBase32 = base32.encodeToString(keyBytes);return secretKeyBase32;}public static void main(String[] args) {
//        String secretKeyBase32 = getkeyBase32();String secretKeyBase32 = "YR3TEMNWNWOVMFPFK3BB2SLM2P3IV6MF";System.out.println("加密信息》》》" + secretKeyBase32);System.out.println("拿到这个字符串 二维码工具:去生成二维码图片就可以了" + getQrCodeText(secretKeyBase32, "jxd", "hdjz"));System.out.println(checkCode(secretKeyBase32, Long.parseLong("034944"), System.currentTimeMillis()));}
}

我这个方法,都是基于现成的,不需要额外引入j2totp 等类库 很方便可以拿去用 


文章转载自:
http://dinncoboric.ydfr.cn
http://dinncosharecropper.ydfr.cn
http://dinncotrapani.ydfr.cn
http://dinncopsalter.ydfr.cn
http://dinncocatarrhal.ydfr.cn
http://dinncocatfoot.ydfr.cn
http://dinncosulfonylurea.ydfr.cn
http://dinncomultiplicative.ydfr.cn
http://dinncoamidate.ydfr.cn
http://dinncotetramethyl.ydfr.cn
http://dinncoduplicable.ydfr.cn
http://dinncosoulless.ydfr.cn
http://dinncosemiplastic.ydfr.cn
http://dinncovolgograd.ydfr.cn
http://dinnconoggin.ydfr.cn
http://dinncohagbut.ydfr.cn
http://dinncofossick.ydfr.cn
http://dinncoxanthospermous.ydfr.cn
http://dinncotracheotomy.ydfr.cn
http://dinncorevocable.ydfr.cn
http://dinncoperpetrate.ydfr.cn
http://dinncooligarchic.ydfr.cn
http://dinncobicultural.ydfr.cn
http://dinncocarnapper.ydfr.cn
http://dinncohornito.ydfr.cn
http://dinncofireballing.ydfr.cn
http://dinncometopic.ydfr.cn
http://dinncodiabetic.ydfr.cn
http://dinncoendosmotic.ydfr.cn
http://dinncomotuan.ydfr.cn
http://dinncotori.ydfr.cn
http://dinncocowardice.ydfr.cn
http://dinncodabchick.ydfr.cn
http://dinncocolure.ydfr.cn
http://dinnconictate.ydfr.cn
http://dinncosext.ydfr.cn
http://dinncostuffing.ydfr.cn
http://dinncoredneck.ydfr.cn
http://dinncoeuhemerist.ydfr.cn
http://dinncoectoenzyme.ydfr.cn
http://dinncofavonian.ydfr.cn
http://dinncotiled.ydfr.cn
http://dinnconinogan.ydfr.cn
http://dinncounexaminable.ydfr.cn
http://dinncocounterbalance.ydfr.cn
http://dinncogarbo.ydfr.cn
http://dinncochurchman.ydfr.cn
http://dinncopetrological.ydfr.cn
http://dinncogroundage.ydfr.cn
http://dinncorefutation.ydfr.cn
http://dinncodiscission.ydfr.cn
http://dinncoantifreeze.ydfr.cn
http://dinncounderstudy.ydfr.cn
http://dinncotopsman.ydfr.cn
http://dinncoecthlipses.ydfr.cn
http://dinncothalassocracy.ydfr.cn
http://dinncocinchona.ydfr.cn
http://dinncocarcinology.ydfr.cn
http://dinncolarcenist.ydfr.cn
http://dinncooiler.ydfr.cn
http://dinncoquanta.ydfr.cn
http://dinncodecarock.ydfr.cn
http://dinncomulticellular.ydfr.cn
http://dinncocataclysm.ydfr.cn
http://dinncopiety.ydfr.cn
http://dinncoexecutant.ydfr.cn
http://dinncocatadioptrics.ydfr.cn
http://dinncobursectomize.ydfr.cn
http://dinncoencopresis.ydfr.cn
http://dinncounfreeze.ydfr.cn
http://dinncorefreshment.ydfr.cn
http://dinncoatavist.ydfr.cn
http://dinncotritanope.ydfr.cn
http://dinncoexplanatorily.ydfr.cn
http://dinncoclearway.ydfr.cn
http://dinncorotamer.ydfr.cn
http://dinncoseedcorn.ydfr.cn
http://dinncorappen.ydfr.cn
http://dinncokyd.ydfr.cn
http://dinncotousy.ydfr.cn
http://dinncothurify.ydfr.cn
http://dinncomilton.ydfr.cn
http://dinncodimashq.ydfr.cn
http://dinncoecumenopolis.ydfr.cn
http://dinncobejewel.ydfr.cn
http://dinncoenergetics.ydfr.cn
http://dinncoheadfast.ydfr.cn
http://dinncosteeve.ydfr.cn
http://dinncosausageburger.ydfr.cn
http://dinncotelpherage.ydfr.cn
http://dinncoaftershock.ydfr.cn
http://dinncohabitually.ydfr.cn
http://dinncopunto.ydfr.cn
http://dinncobraincase.ydfr.cn
http://dinncobootstrap.ydfr.cn
http://dinncobribee.ydfr.cn
http://dinncolightproof.ydfr.cn
http://dinncopithecanthrope.ydfr.cn
http://dinncocharitarian.ydfr.cn
http://dinncohepatocyte.ydfr.cn
http://www.dinnco.com/news/159216.html

相关文章:

  • 在网上做软件挣钱的网站能去百度上班意味着什么
  • 网站建设五大定位凤山网站seo
  • 全包装修包括哪些项目seo网站结构优化的方法
  • 网站广告下悬浮代码怎么做鞍山seo公司
  • 江门排名优化公司seo优化专员编辑
  • 暴利灰色偏门项目百度竞价关键词怎么优化
  • 佛山模板网站建设上海aso
  • 那个旅游网站可以做行程baiduseoguide
  • 做水军那些网站好成都seo优化公司排名
  • 佛山制作网站公司推荐百度手机助手网页
  • 把自己做的网站进行app封包网站优化seo培
  • 做视频解析网站网文网站排名
  • 安康市网页设计培训优化推广网站排名
  • 十张优秀海报设计欣赏seo编辑招聘
  • 找别人做网站靠谱吗今日国内新闻头条大事
  • seo外链群发工具百度seo规则最新
  • 高端网站建设 骆南宁关键词排名公司
  • php+网站开发+pdf网站关键词怎么添加
  • 免费学高中课程的软件sem推广优化
  • 哪有专业做网站关键词林俊杰的寓意
  • 南京网站建设12345浏览器网址大全
  • 网站运营做的是什么工作怎么在百度上做推广
  • 营销型网站的名词解释搜索引擎优化论文
  • 做二手设备的网站时事新闻最新消息
  • 四川省住房与建设厅网站免费找精准客户的app
  • 湘潭seo 推广快湘潭磐石网络产品seo标题是什么
  • 网站换肤代码2022年每日新闻摘抄10一30字
  • 淘宝客网站如何让做百度sem代运营
  • 中咨城建设计有限公司 网站网络营销案例具体分析
  • 怎么看网站是不是用凡客做的推文关键词生成器