資源簡介
C#使用 谷歌身份認證器,動態口令,GoogleAuthenticator 基于時間的一次性密碼
代碼片段和文件信息
using?System;
namespace?GoogleAuthorization
{
????public?static?class?base32
????{
????????public?static?byte[]?ToBytes(string?input)
????????{
????????????if?(string.IsNullOrEmpty(input))
????????????{
????????????????throw?new?ArgumentNullException(“input“);
????????????}
????????????input?=?input.TrimEnd(‘=‘);?
????????????int?byteCount?=?input.Length?*?5?/?8;?
????????????byte[]?returnArray?=?new?byte[byteCount];
????????????byte?curByte?=?0?bitsRemaining?=?8;
????????????int?mask?=?0?arrayIndex?=?0;
????????????foreach?(char?c?in?input)
????????????{
????????????????int?cValue?=?CharToValue(c);
????????????????if?(bitsRemaining?>?5)
????????????????{
????????????????????mask?=?cValue?<(bitsRemaining?-?5);
????????????????????curByte?=?(byte)(curByte?|?mask);
????????????????????bitsRemaining?-=?5;
????????????????}
????????????????else
????????????????{
????????????????????mask?=?cValue?>>?(5?-?bitsRemaining);
????????????????????curByte?=?(byte)(curByte?|?mask);
????????????????????returnArray[arrayIndex++]?=?curByte;
????????????????????curByte?=?(byte)(cValue?<(3?+?bitsRemaining));
????????????????????bitsRemaining?+=?3;
????????????????}
????????????}
????????????if?(arrayIndex?!=?byteCount)
????????????{
????????????????returnArray[arrayIndex]?=?curByte;
????????????}
????????????return?returnArray;
????????}
????????public?static?string?ToString(byte[]?input)
????????{
????????????if?(input?==?null?||?input.Length?==?0)
????????????{
????????????????throw?new?ArgumentNullException(“input“);
????????????}
????????????int?charCount?=?(int)Math.Ceiling(input.Length?/?5d)?*?8;
????????????char[]?returnArray?=?new?char[charCount];
????????????byte?nextChar?=?0?bitsRemaining?=?5;
????????????int?arrayIndex?=?0;
????????????foreach?(byte?b?in?input)
????????????{
????????????????nextChar?=?(byte)(nextChar?|?(b?>>?(8?-?bitsRemaining)));
????????????????returnArray[arrayIndex++]?=?ValueToChar(nextChar);
????????????????if?(bitsRemaining?4)
????????????????{
????????????????????nextChar?=?(byte)((b?>>?(3?-?bitsRemaining))?&?31);
????????????????????returnArray[arrayIndex++]?=?ValueToChar(nextChar);
????????????????????bitsRemaining?+=?5;
????????????????}
????????????????bitsRemaining?-=?3;
????????????????nextChar?=?(byte)((b?<????????????}
????????????if?(arrayIndex?!=?charCount)
????????????{
????????????????returnArray[arrayIndex++]?=?ValueToChar(nextChar);
????????????????while?(arrayIndex?!=?charCount)?returnArray[arrayIndex++]?=?‘=‘;?
????????????}
????????????return?new?string(returnArray);
????????}
????????private?static?int?CharToValue(char?c)
????????{
????????????var?value?=?(int)c;
????????????if?(value?91?&&?value?>?64)
????????????{
????????????????return?value?-?65;
????????????}
????????????if?(value?56?&&?value?>?49)
????????????{
????????????????return?value?-?24;
????????????}
????????????if?(value?123?&&?value?>?96)
????????????{
????????????????return?value?-?97;
?????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-11-13?01:22??GoogleAuthenticator-master\
?????文件????????5850??2019-11-13?01:22??GoogleAuthenticator-master\.gitignore
?????文件????????1004??2019-11-13?01:22??GoogleAuthenticator-master\GoogleAuthenticator.sln
?????目錄???????????0??2019-11-13?01:22??GoogleAuthenticator-master\GoogleAuthorization\
?????文件????????3453??2019-11-13?01:22??GoogleAuthenticator-master\GoogleAuthorization\ba
?????文件????????3420??2019-11-13?01:22??GoogleAuthenticator-master\GoogleAuthorization\GoogleAuthenticator.cs
?????文件????????2545??2019-11-13?01:22??GoogleAuthenticator-master\GoogleAuthorization\GoogleAuthenticator.csproj
?????文件?????????873??2019-11-13?01:22??GoogleAuthenticator-master\GoogleAuthorization\Program.cs
?????目錄???????????0??2019-11-13?01:22??GoogleAuthenticator-master\GoogleAuthorization\Properties\
?????文件????????1326??2019-11-13?01:22??GoogleAuthenticator-master\GoogleAuthorization\Properties\AssemblyInfo.cs
?????文件????????1028??2019-11-13?01:22??GoogleAuthenticator-master\README.md
- 上一篇:調取本機攝像頭拍照
- 下一篇:ASP.Net文件上傳管理源碼
評論
共有 條評論