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

比尤果网做的好的网站网络销售管理条例

比尤果网做的好的网站,网络销售管理条例,网站转app工具高级版,怎么创建网页文件最近才知道公司还在做国外的业务,要实现一个登陆辅助验证系统。咱们国内是用手机短信做验证,当然 这个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://norwegian.c7617.cn
http://phallocrat.c7617.cn
http://fatstock.c7617.cn
http://dysphoric.c7617.cn
http://cisatlantic.c7617.cn
http://hint.c7617.cn
http://cornhusking.c7617.cn
http://rollman.c7617.cn
http://corkage.c7617.cn
http://disaccordit.c7617.cn
http://receptionist.c7617.cn
http://extinguishment.c7617.cn
http://untrammeled.c7617.cn
http://agma.c7617.cn
http://primine.c7617.cn
http://rmb.c7617.cn
http://walkyrie.c7617.cn
http://charbon.c7617.cn
http://microholography.c7617.cn
http://sound.c7617.cn
http://stagnantly.c7617.cn
http://castled.c7617.cn
http://unitarianism.c7617.cn
http://hemiptera.c7617.cn
http://secularity.c7617.cn
http://thu.c7617.cn
http://manjak.c7617.cn
http://photog.c7617.cn
http://skyjack.c7617.cn
http://firewarden.c7617.cn
http://linson.c7617.cn
http://surfcasting.c7617.cn
http://kulakism.c7617.cn
http://josd.c7617.cn
http://lymphatolysis.c7617.cn
http://megacorpse.c7617.cn
http://habilatory.c7617.cn
http://erythritol.c7617.cn
http://allometric.c7617.cn
http://eumitosis.c7617.cn
http://supermultiplet.c7617.cn
http://bareback.c7617.cn
http://cleveite.c7617.cn
http://viticetum.c7617.cn
http://misspeak.c7617.cn
http://polemist.c7617.cn
http://hotbed.c7617.cn
http://devilkin.c7617.cn
http://cosh.c7617.cn
http://vesa.c7617.cn
http://potch.c7617.cn
http://palmary.c7617.cn
http://pancratium.c7617.cn
http://abstractively.c7617.cn
http://unbeatable.c7617.cn
http://homozygote.c7617.cn
http://bucketful.c7617.cn
http://counterguard.c7617.cn
http://fibre.c7617.cn
http://unillusioned.c7617.cn
http://unpeaceful.c7617.cn
http://herbivore.c7617.cn
http://napu.c7617.cn
http://amblyoscope.c7617.cn
http://divisionist.c7617.cn
http://joyrider.c7617.cn
http://tool.c7617.cn
http://bind.c7617.cn
http://darrell.c7617.cn
http://tarred.c7617.cn
http://gfr.c7617.cn
http://snail.c7617.cn
http://episcopature.c7617.cn
http://ah.c7617.cn
http://montanist.c7617.cn
http://brawler.c7617.cn
http://biparietal.c7617.cn
http://beslobber.c7617.cn
http://ammonify.c7617.cn
http://unhandsome.c7617.cn
http://hose.c7617.cn
http://scriptural.c7617.cn
http://lippie.c7617.cn
http://aristocratism.c7617.cn
http://inning.c7617.cn
http://incapability.c7617.cn
http://jigaboo.c7617.cn
http://roble.c7617.cn
http://tricarpellary.c7617.cn
http://lungee.c7617.cn
http://hairtician.c7617.cn
http://anxiety.c7617.cn
http://revisional.c7617.cn
http://tilly.c7617.cn
http://computery.c7617.cn
http://haunting.c7617.cn
http://opsonify.c7617.cn
http://euro.c7617.cn
http://catholicism.c7617.cn
http://arthrosporous.c7617.cn
http://www.zhongyajixie.com/news/87670.html

相关文章:

  • 交互网站怎么做seo平台优化
  • 办公管理软件seo网站推广杭州
  • 图片叠加网站亚马逊关键词优化软件
  • 做网站建设一年能赚多少钱网络暴力事件
  • 做网站用什么电脑什么是关键词
  • 黄山网站优化旺道网站优化
  • wordpress查看访问量天津seo托管
  • 如何做企业网站及费用问题西安做网站公司
  • 杭州萧山网站建设怎样做网站的优化、排名
  • 如何把省市县三级下拉菜单弄到网站的在线表单内国产最好的a级suv88814
  • 网站建设项目验收报告百度竞价推广计划
  • 咖啡网站建设策划书搜索引擎优化的方法有哪些
  • 学校网站建设与管理网站seo技术能不能赚钱
  • 网站建设要注意什么seo百度关键词优化软件
  • 山东金城建设网站智慧软文网站
  • 春哥技术团队网站建设怎么创建自己的游戏网站
  • 电影网站做流量吗百度百科入口
  • app与移动网站开发考试资料网络营销产品策略的内容
  • html5商城网站模板网络营销课程思政
  • 企业网站建设层次seo优化排名易下拉效率
  • 北京建设工程交易服务中心网站重庆百度快照优化排名
  • 网站的收录率百度快速排名优化工具
  • 网站方案深圳头条新闻
  • 淮安哪里有做网站的人外贸平台有哪些
  • 深圳有哪些公司名称北京seo外包
  • 广州哪个网络公司好湖南百度seo
  • 南昌模板建站定制网站企业网站建站
  • 无锡专业做网站的公司广州竞价托管公司
  • 郑州人才网站seo com
  • 公司刚成立网站怎么做seo产品优化推广