public void GetUriSuccess(HashAlgorithmType hashAlgorithm, byte period, byte digits) { var id = Guid.NewGuid().ToString(); var secret = new byte[32]; using (var rng = RandomNumberGenerator.Create()) { rng.GetBytes(secret); } var options = GetOptions(); options.Value.HashAlgorithm = hashAlgorithm; options.Value.NumberOfDigits = digits; options.Value.PeriodInSeconds = period; var service = new AuthenticatorService(options, new DefaultSystemTime()); var uri = service.GetUri(id, secret); Assert.Equal(string.Format("otpauth://totp/{0}%3A{1}?secret={2}&issuer={0}&algorithm={3}&digits={4}&period={5}", Issuer, id, Base32Encoding.Encode(secret).Trim('='), hashAlgorithm.ToString(), digits, period ), uri); }
public void MoreTest(string expected, string actual) { //https://tools.ietf.org/html/rfc4648#section-10 Assert.Equal(expected, Base32Encoding.Encode(Encoding.UTF8.GetBytes(actual))); }
public void TestHello() { var test = Encoding.UTF8.GetBytes("Hello!").Concat(new byte[] { 0xDE, 0xAD, 0xBE, 0xEF }).ToArray(); Assert.Equal("JBSWY3DPEHPK3PXP", Base32Encoding.Encode(test)); }
public void NullInput() { Assert.Throws <ArgumentNullException>(() => Base32Encoding.Encode(null)); }