找不到类型或命名空间名称“GoogleTOTP”(您是否缺少using指令或程序集引用?) [英] The type or namespace name 'GoogleTOTP' could not be found (are you missing a using directive or an assembly reference?)

查看:96
本文介绍了找不到类型或命名空间名称“GoogleTOTP”(您是否缺少using指令或程序集引用?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
//using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Security.Cryptography;
public partial class Default2 : System.Web.UI.Page
{
  GoogleTOTP tf;

    private long lastInterval;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //pictureBox1.Image = tf.GenerateImage(pictureBox1.Width, pictureBox1.Height, txtUserEmail.Text);

        Image1.ImageUrl = tf.GenerateImage(Image1.Width, Image1.Height, txtUserEmail.Text);
        txtOutput.Text = tf.GeneratePin();
    }
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        long thisInterval = tf.getCurrentInterval();
        if (lastInterval != thisInterval)
        {
            txtOutput.Text = tf.GeneratePin();
            lastInterval = thisInterval;
        }
    }
}



The type or namespace name 'GoogleTOTP' could not be found (are you missing a using directive or an assembly reference?)	



i have also one class




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Net;
using System.IO;
using System.Drawing;
using GoogleAuth;
namespace GoogleAuth
{
   public  class GoogleTOTP
	{
		RNGCryptoServiceProvider rnd;
		protected string unreservedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";

		private int intervalLength;
		private int pinCodeLength;
		private int pinModulo;

		private byte[] randomBytes = new byte[10];

		public GoogleTOTP()
		{
			rnd = new RNGCryptoServiceProvider();

			pinCodeLength = 6;
			intervalLength = 30;
			pinModulo = (int)Math.Pow(10, pinCodeLength);

			rnd.GetBytes(randomBytes);
		}

		public byte[] getPrivateKey()
		{
			return randomBytes;
		}

		/// <summary>
		/// Generates a PIN of desired length when given a challenge (counter)
		/// </summary>
		/// <param name="challenge">Counter to calculate hash</param>
		/// <returns>Desired length PIN</returns>
		private String generateResponseCode(long challenge, byte[] randomBytes)
		{
			HMACSHA1 myHmac = new HMACSHA1(randomBytes);
			myHmac.Initialize();

			byte[] value = BitConverter.GetBytes(challenge);
			Array.Reverse(value); //reverses the challenge array due to differences in c# vs java
			myHmac.ComputeHash(value);
			byte[] hash = myHmac.Hash;
			int offset = hash[hash.Length - 1] & 0xF;
			byte[] SelectedFourBytes = new byte[4];
			//selected bytes are actually reversed due to c# again, thus the weird stuff here
			SelectedFourBytes[0] = hash[offset];
			SelectedFourBytes[1] = hash[offset + 1];
			SelectedFourBytes[2] = hash[offset + 2];
			SelectedFourBytes[3] = hash[offset + 3];
			Array.Reverse(SelectedFourBytes);
			int finalInt = BitConverter.ToInt32(SelectedFourBytes, 0);
			int truncatedHash = finalInt & 0x7FFFFFFF; //remove the most significant bit for interoperability as per HMAC standards
			int pinValue = truncatedHash % pinModulo; //generate 10^d digits where d is the number of digits
			return padOutput(pinValue);
		}

		/// <summary>
		/// Gets current interval number since Unix Epoch based on given interval length
		/// </summary>
		/// <returns>Current interval number</returns>
		public long getCurrentInterval()
		{
			TimeSpan TS = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
			long currentTimeSeconds = (long)Math.Floor(TS.TotalSeconds);
			long currentInterval = currentTimeSeconds / intervalLength; // 30 Seconds
			return currentInterval;
		}

		/// <summary>
		/// Pads the output string with leading zeroes just in case the result is less than the length of desired digits
		/// </summary>
		/// <param name="value">Value to pad</param>
		/// <returns>Padded Result</returns>
		private String padOutput(int value)
		{
			String result = value.ToString();
			for (int i = result.Length; i < pinCodeLength; i++)
			{
				result = "0" + result;
			}
			return result;
		}

		/// <summary>
		/// This is a different Url Encode implementation since the default .NET one outputs the percent encoding in lower case.
		/// While this is not a problem with the percent encoding spec, it is used in upper case throughout OAuth
		/// </summary>
		/// <param name="value">The value to Url encode</param>
		/// <returns>Returns a Url encoded string</returns>
		protected string UrlEncode(string value)
		{
			StringBuilder result = new StringBuilder();

			foreach (char symbol in value)
			{
				if (unreservedChars.IndexOf(symbol) != -1)
				{
					result.Append(symbol);
				}
				else
				{
					result.Append('%' + String.Format("{0:X2}", (int)symbol));
				}
			}

			return result.ToString();
		}

		public Image GenerateImage(int width, int height, string email)
		{
			string randomString = CreativeCommons.Transcoder.Base32Encode(randomBytes);
            string ProvisionUrl = UrlEncode(String.Format("otpauth://totp/me@mywindow.com?secret=xFwkAguLCqLPsyxLowR5BWjU", email, randomString));
			string url = String.Format("http://chart.apis.google.com/chart?cht=qr&chs={0}x{1}&chl={2}", width, height, ProvisionUrl);

			WebClient wc = new WebClient();
			var data = wc.DownloadData(url);

			using (var imageStream = new MemoryStream(data))
			{
				return new Bitmap(imageStream);
			}
		}

		public string GeneratePin()
		{
			return generateResponseCode(getCurrentInterval(), randomBytes);
		}

	}
}

推荐答案

你的班级 GoogleTOTP 位于命名空间 GoogleAuth 中,但您不要直接引用它,或通过使用声明。



您可以手动限定它,但简单的方法是将文本光标放在VS抱怨的类名中( GoogleTOTP 在这种情况下)并且在开头会出现一条蓝线。将鼠标悬停在蓝线上,然后会出现一个下拉菜单。

打开下拉列表,VS会给出一个可以为您实现的可能解决方案列表。这些将包括将限定名称添加到此实例,并使用语句添加相应的

如果蓝线没有出现,那么VS找不到班级,你需要查看你的拼写/字符案例/参考文献。
Your class GoogleTOTP is in the namespace GoogleAuth, but you don;t refer to it directly, or via a using statement.

You could qualify it manually, but the easy way is to put the text cursor in the class name that VS is complaining about (GoogleTOTP in this case) and a blue line will appear at the beginning. Hover the mouse over the blue line, and a drop down will appear.
Open the dropdown, and VS will give you a list of possible solutions, which it can implement for you. These will include adding the qualified name to this instance, and adding the appropriate using statement.
If the blue line doesn't appear, then VS can't find the class at all, and you need to look at your spelling / character case / references.


这篇关于找不到类型或命名空间名称“GoogleTOTP”(您是否缺少using指令或程序集引用?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆