資源簡介
從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
評論
共有 條評論