1
0
mirror of synced 2025-02-17 11:18:32 +01:00
2024-11-19 01:32:03 +08:00

21 lines
562 B
C#

using System.Text;
using OtpNet;
namespace Application.Utils;
public class TotpUtils
{
public static Totp MakeTotp(uint baid)
{
var secretKey = (baid * 765 + 2023).ToString();
var base32String = Base32Encoding.ToString(Encoding.UTF8.GetBytes(secretKey));
var base32Bytes = Base32Encoding.ToBytes(base32String);
return new Totp(base32Bytes, step: 999999999);
}
public static bool VerifyOtp(string otp, uint baid)
{
var totp = MakeTotp(baid);
return totp.VerifyTotp(otp, out _);
}
}