资源简介
从OATH标准资料整理的OTP算法Java工程代码。
完整Eclipse工程代码,使用JCE。
包括:HOTP(事件OTP),TOTP(时间OTP)和 OCRA(挑战与应答OTP)。
完全来源于网上标准文档,RFC6226,RFC6238,RFC6287。

代码片段和文件信息
/**
Copyright (c) 2011 IETF Trust and the persons identified as
authors of the code. All rights reserved.
Redistribution and use in source and binary forms with or without
modification is permitted pursuant to and subject to the license
terms contained in the Simplified BSD License set forth in Section
4.c of the IETF Trust’s Legal Provisions Relating to IETF Documents
(http://trustee.ietf.org/license-info).
*/
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.math.BigInteger;
/**
* This an example implementation of OCRA. Visit www.openauthentication.org for
* more information.
*
* @author Johan Rydell PortWise
*/
public class OCRA {
private OCRA() {
}
/**
* 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_sha1(String crypto byte[] keyBytes byte[] text) {
Mac hmac = null;
try {
hmac = Mac.getInstance(crypto);
SecretKeySpec macKey = new SecretKeySpec(keyBytes “RAW“);
hmac.init(macKey);
return hmac.doFinal(text);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private static final int[] DIGITS_POWER
// 0 1 2 3 4 5 6 7 8
= { 1 10 100 1000 10000 100000 1000000 10000000 100000000 };
/**
* This method converts 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 converted
byte[] bArray = new BigInteger(“10“ + hex 16).toByteArray();
// Copy all the REAL bytes not the “first“
byte[] ret = new byte[bArray.length - 1];
System.arraycopy(bArray 1 ret 0 ret.length);
return ret;
}
/**
* This method generates an OCRA HOTP value for the given set of parameters.
*
* @param ocraSuite
* the OCRA Suite
* @param key
* the shared secret HEX encoded
* @param counter
* the counter that changes on a per use basis HEX encoded
* @param question
* the challenge question HEX encoded
* @param password
* a password that can be used HEX encoded
* @param sessionInformation
* Static information that identifies the current session Hex
* encoded
* @param timeStamp
* a value that reflects a time
*
* @return A numeric String in base 10 that includes
* {@link truncationDigits} digits
*/
static public String generateOCRA(String ocraSuite String key
String counte
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-12-12 17:23 OTPProject\
文件 307 2011-12-16 11:39 OTPProject\.classpath
目录 0 2017-12-12 17:23 __MACOSX\
目录 0 2017-12-12 17:23 __MACOSX\OTPProject\
文件 212 2011-12-16 11:39 __MACOSX\OTPProject\._.classpath
文件 386 2011-12-06 18:26 OTPProject\.project
文件 212 2011-12-06 18:26 __MACOSX\OTPProject\._.project
目录 0 2017-12-12 17:23 OTPProject\src\
文件 8298 2011-12-07 09:21 OTPProject\src\OCRA.java
目录 0 2017-12-12 17:23 __MACOSX\OTPProject\src\
文件 212 2011-12-07 09:21 __MACOSX\OTPProject\src\._OCRA.java
目录 0 2017-12-12 17:23 OTPProject\src\org\
目录 0 2017-12-12 17:23 OTPProject\src\org\openauthentication\
目录 0 2017-12-12 17:23 OTPProject\src\org\openauthentication\otp\
文件 6473 2011-12-06 18:32 OTPProject\src\org\openauthentication\otp\OneTimePasswordAlgorithm.java
目录 0 2017-12-12 17:23 __MACOSX\OTPProject\src\org\
目录 0 2017-12-12 17:23 __MACOSX\OTPProject\src\org\openauthentication\
目录 0 2017-12-12 17:23 __MACOSX\OTPProject\src\org\openauthentication\otp\
文件 212 2011-12-06 18:32 __MACOSX\OTPProject\src\org\openauthentication\otp\._OneTimePasswordAlgorithm.java
文件 1083 2011-12-07 09:21 OTPProject\src\org\openauthentication\otp\OTPTest.java
文件 212 2011-12-07 09:21 __MACOSX\OTPProject\src\org\openauthentication\otp\._OTPTest.java
文件 176 2017-12-12 17:23 __MACOSX\OTPProject\src\org\openauthentication\._otp
文件 176 2017-12-12 17:23 __MACOSX\OTPProject\src\org\._openauthentication
文件 176 2017-12-12 17:23 __MACOSX\OTPProject\src\._org
文件 10931 2011-12-07 09:30 OTPProject\src\TestOCRA.java
文件 212 2011-12-07 09:30 __MACOSX\OTPProject\src\._TestOCRA.java
文件 7675 2011-12-07 09:15 OTPProject\src\TOTP.java
文件 212 2011-12-07 09:15 __MACOSX\OTPProject\src\._TOTP.java
文件 176 2017-12-12 17:23 __MACOSX\OTPProject\._src
文件 176 2017-12-12 17:23 __MACOSX\._OTPProject
- 上一篇:android蓝牙开发
- 下一篇:jcommon-1.0.15.jar
相关资源
- java串口通信全套完整代码-导入eclip
- jsonarray所必需的6个jar包.rar
- 三角网构TIN生成算法,Java语言实现
- java代码编写将excel数据导入到mysql数据
- Java写的cmm词法分析器源代码及javacc学
- JAVA JSP公司财务管理系统 源代码 论文
- JSP+MYSQL旅行社管理信息系统
- 推荐算法的JAVA实现
- 基于Java的酒店管理系统源码(毕业设
- java-图片识别 图片比较
- android毕业设计
- java23种设计模式+23个实例demo
- java Socket发送/接受报文
- JAVA828436
- java界面美化 提供多套皮肤直接使用
- 在线聊天系统(java代码)
- 基于Java的图书管理系统807185
- java中实现将页面数据导入Excel中
- java 企业销售管理系统
- java做的聊天系统(包括正规课程设计
- Java编写的qq聊天室
- 商店商品管理系统 JAVA写的 有界面
- JAVA开发聊天室程序
- 在linux系统下用java执行系统命令实例
- java期末考试试题两套(答案) 选择(
- JAVA3D编程示例(建模、交互)
- Java 文件加密传输
- java做的房产管理系统
- 基于jsp的bbs论坛 非常详细
- [免费]java实现有障碍物的贪吃蛇游戏
评论
共有 条评论