GoEasy-OTP > C#生成GoEasy-OTP
public string goEasyOTP(string secretKey)
{
string otp = null;
byte[] encrypted = null;
string currentTimeMills=string.Format("000{0}",(long)(DateTime.UtcNow-new
DateTime(1970,1,1,0,0,0,DateTimeKind.Utc)).TotalMilliseconds);
//"0001490325990593"
byte[] byteSecretKey = Encoding.ASCII.GetBytes(secretKey);
using (AesManaged aesAlg = new AesManaged(){Key = byteSecretKey,Mode = CipherMode.ECB,Padding = PaddingMode.None})
{
ICryptoTransform encryptor = aesAlg.CreateEncryptor();
using (MemoryStream msEncrypt = new MemoryStream())
{
using(CryptoStream csEncrypt = new CryptoStream(msEncrypt,encryptor,CryptoStreamMode.Write))
{
using(StreamWriter swEncrypt = new StreamWriter(csEncrypt))
{
swEncrypt.Write(currentTimeMills);
}
encrypted = msEncrypt.ToArray();
}
}
}
otp = Convert.ToBase64String(encrypted);
return otp;
}
secret key:86726e4356dce2d3
系统毫秒数:0001490325990593
GoEasy-otp:+rOKqbTZioistsdMrhon0A==
什么是GoEasy-OTP?
如何使用GoEasy-OTP?
验证GoEasy-OTP生成结果
Java生成GoEasy-OTP
PHP生成GoEasy-OTP
Python生成GoEasy-OTP
Ruby生成GoEasy-OTP
C#生成GoEasy-OTP