Inheritance: HashAlgorithm
示例#1
0
 /// <summary>
 /// //Returns a SHA1 hash of the value of msDS-UpdateScript of Partitions container.
 /// </summary>
 public static byte[] PrepareScriptHashBody(string updateScript)
 {
     byte[] unicodeBytes = System.Text.Encoding.Unicode.GetBytes(updateScript);
     System.Security.Cryptography.SHA1 sha = System.Security.Cryptography.SHA1CryptoServiceProvider.Create();
     byte[] hash1 = sha.ComputeHash(unicodeBytes);
     return(hash1);
 }
示例#2
0
 public static byte[] SHA1(byte[] data)
 {
     using (System.Security.Cryptography.SHA1 sha1 = System.Security.Cryptography.SHA1.Create())
     {
         return(ComputeHash(sha1, data));
     }
 }
示例#3
0
    private string EncryptPasswrod(string password)
    {
        System.Security.Cryptography.SHA1 sha = System.Security.Cryptography.SHA1.Create();
        string hashed = System.Convert.ToBase64String(sha.ComputeHash(System.Text.UnicodeEncoding.Unicode.GetBytes(password)));

        return(hashed.Length > 49 ? hashed.Substring(0, 49) : hashed);
    }
        public SHA1StreamReader(Stream input)
        {
            this.input = input;

            this.sha1 = SHA1.Create();
            this.position = 0L;
        }
示例#5
0
    //----------------------------------------------------------------------------

    /*!
     *          @brief	セキュリティ用チェックサムの構築
     */
    //----------------------------------------------------------------------------
    static public string CreatePacketCheckSum(string strPacketJson,
                                              SERVER_API packetAPI = SERVER_API.SERVER_API_NONE,
                                              string uuid          = null)
    {
        {
            //sha1
            System.Security.Cryptography.SHA1 sha1 = System.Security.Cryptography.SHA1.Create();

            string checkSumUuid = (uuid != null) ? uuid : LocalSaveManager.Instance.LoadFuncUUID();
            //ユーザー作成時は正常終了後にuuidセットしてるので送ったjsonからuuid取り出す
            if (packetAPI == SERVER_API.SERVER_API_USER_CREATE)
            {
                //JsonData型にパース
                JsonData sendMessageJsonData = JsonMapper.ToObject(strPacketJson);
                //パース後のJsonData型にuuidがあるか?
                if (true == (sendMessageJsonData as IDictionary).Contains("uuid"))
                {
                    //jsonのuuidを設定
                    checkSumUuid = (string)sendMessageJsonData["uuid"];
                }
            }

            var sha1Bs = sha1.ComputeHash(new UTF8Encoding().GetBytes(strPacketJson + checkSumUuid));
            strPacketJson = BitConverter.ToString(sha1Bs).ToLower().Replace("-", "");
        }

        return("");
    }
示例#6
0
	}//ComputeCRC32


	/// <summary>
	/// 获取文件的SHA1
	/// </summary>
	/// <param name="fileName"></param>
	/// <returns></returns>
	public static String GetSHA1(String fileName)
	{
		String hashSHA1 = String.Empty;
		//检查文件是否存在,如果文件存在则进行计算,否则返回空值
		if (File.Exists(fileName))
		{
			using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
			{
				//计算文件的SHA1值
				System.Security.Cryptography.SHA1 calculator = System.Security.Cryptography.SHA1.Create();
				Byte[] buffer = calculator.ComputeHash(fileStream);
				calculator.Clear();
				//将字节数组转换成十六进制的字符串形式
				StringBuilder stringBuilder = new StringBuilder();
				for (int bufferIdx = 0; bufferIdx < buffer.Length; bufferIdx++)
				{
					stringBuilder.Append(buffer[bufferIdx].ToString("x2"));
				}
				hashSHA1 = stringBuilder.ToString();

			}//关闭文件流
		}
		else
		{
			Console.Error.WriteLine("{0}文件找不到!", fileName);
		}
		return hashSHA1;
	}//end GetSHA1
示例#7
0
        /// <summary>
        /// Hashes the specified value using utf8 encoding.
        /// </summary>
        /// <param name="alg">The SHA1 instance to use.</param>
        /// <param name="value">The string to hash.</param>
        /// <returns></returns>
        public static Sha1 HashData(this crypt.SHA1 alg, string value)
        {
            if (alg == null)
            {
                throw new ArgumentNullException(nameof(alg));
            }
            if (value is null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (value.Length == 0)
            {
                return(s_empty1);
            }

            int maxLen = Encoding.UTF8.GetMaxByteCount(value.Length); // Utf8 is 1-4 bpc

            byte[] rented = ArrayPool <byte> .Shared.Rent(maxLen);

            try
            {
                int count = Encoding.UTF8.GetBytes(value, 0, value.Length, rented, 0);

                var span = new ReadOnlySpan <byte>(rented, 0, count);

                Sha1 sha = HashImpl(alg, span);
                return(sha);
            }
            finally
            {
                ArrayPool <byte> .Shared.Return(rented);
            }
        }
示例#8
0
 private static byte[] SHA1(params byte[][] data)
 {
     using (System.Security.Cryptography.SHA1 alg = CryptoNS.SHA1.Create())
     {
         return(alg.ComputeHash(Combine(data)));
     }
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="output"></param>
        public SHA1OutputStream(Stream output)
        {
            this.output = output;

            this.sha1 = SHA1.Create();
            this.position = 0L;
        }
示例#10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        public SHA1InputStream(Stream input)
        {
            this.input = input;

            this.sha1 = SHA1.Create();
            this.position = 0L;
        }
示例#11
0
    public static void CalculaterHash()
    {
        string assetPath    = AssetDatabase.GetAssetPath(Selection.activeObject);
        string absulotePath = Application.dataPath + assetPath.Substring(6);

        FileStream fs = new FileStream(absulotePath, FileMode.Open, FileAccess.Read);

        //md5
        System.Security.Cryptography.MD5 md5calculator = System.Security.Cryptography.MD5.Create();
        byte[]        buffer1 = md5calculator.ComputeHash(fs);
        StringBuilder sb1     = new StringBuilder();

        for (int i = 0; i < buffer1.Length; ++i)
        {
            sb1.Append(buffer1[i].ToString("x2"));
        }

        Debug.LogWarningFormat("MD5:{0}", sb1.ToString());

        System.Security.Cryptography.SHA1 sha1calculator = System.Security.Cryptography.SHA1.Create();
        byte[]        buffer2 = sha1calculator.ComputeHash(fs);
        StringBuilder sb2     = new StringBuilder();

        for (int i = 0; i < buffer2.Length; ++i)
        {
            sb2.Append(buffer2[i].ToString("x2"));
        }

        Debug.LogWarningFormat("SHA1:{0}", sb2.ToString());

        fs.Close();
    }
    static private string Sha1BattleSetting(string values)
    {
        System.Security.Cryptography.SHA1 sha1 = System.Security.Cryptography.SHA1.Create();
        var sha1Bs = sha1.ComputeHash(new UTF8Encoding().GetBytes(values));

        return(BitConverter.ToString(sha1Bs).ToLower().Replace("-", ""));
    }
示例#13
0
        /// <summary>
        /// 将字符串进行SHA1加密
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string SHA1(string str)
        {
            System.Security.Cryptography.SHA1 sha1 = System.Security.Cryptography.SHA1.Create();
            string encoded = BitConverter.ToString(sha1.ComputeHash(Encoding.UTF8.GetBytes(str))).Replace("-", "");

            return(encoded);
        }
示例#14
0
文件: Aich.cs 项目: arucard21/AniDB
 public override void Initialize()
 {
     partHashes = new List<byte[]>();
     blockHashes = new List<byte[]>();
     blockHasher = SHA1.Create();
     nodeHasher = SHA1.Create();
 }
示例#15
0
        public static Hash Compute(byte[] contentData)
        {
            System.Security.Cryptography.SHA1 hashAlgorithm = System.Security.Cryptography.SHA1.Create();
            byte[] hashData = hashAlgorithm.ComputeHash(contentData);

            return(new Hash(hashData));
        }
        public SHA1StreamWriter(Stream output)
        {
            this.output = output;

            this.sha1 = SHA1.Create();
            this.position = 0;
        }
 internal void EnableHashing()
 {
     lock (this) {
         if (null != _hasher) { throw new InvalidOperationException(); }
         _hasher = (SHA1)SHA1.Create();
     }
     return;
 }
示例#18
0
	public void FIPS186_a (string testName, SHA1 hash, byte[] input, byte[] result) 
	{
		byte[] output = hash.ComputeHash (input); 
		Assert.AreEqual (result, output, testName + ".a.1");
		Assert.AreEqual (result, hash.Hash, testName + ".a.2");
		// required or next operation will still return old hash
		hash.Initialize ();
	}
		public HMACSSLv3Verify(byte[] key)
		{
			this.HashSizeValue = 288;
			this.KeyValue = (byte[]) key.Clone();
			
			_md5 = new MD5CryptoServiceProvider();
			_sha1 = new SHA1CryptoServiceProvider();
		}
示例#20
0
		/**** Cryptography *****/

		public static string Hash(string data)
		{
			var bytes = Encoding.UTF8.GetBytes(data);
			if (sha1 == null)
				sha1 = new SHA1Managed();
			var hash = sha1.ComputeHash(bytes);
			return BytesToString(hash);
		}
 string Hash(SHA1 sha, int number)
 {
     byte[] hashArray = sha.ComputeHash(Encoding.ASCII.GetBytes(number.ToString()));
     string newHash = "";
     for (int hashPos = 0; hashPos < hashArray.Length; hashPos++)
         newHash += hashArray[hashPos].ToString("x2");
     return newHash;
 }
示例#22
0
	// Constructors.
	public HMACSHA1()
			{
				HashSizeValue = 160;
				KeyValue = new byte [64];
				CryptoMethods.GenerateRandom(KeyValue, 0, 64);
				alg = null;
				algName = CryptoConfig.SHA1Default;
			}
示例#23
0
 static WSClient()
 {
     Encryptor = SHA1.Create();
     SpaceKey = StreamHelpers.Encoder.GetBytes(" ")[0];
     KeyPattern = StreamHelpers.Encoder.GetBytes("************************258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
     KeyPrefix = StreamHelpers.Encoder.GetBytes("Sec-WebSocket-Key:");
     HandshakePatternA = StreamHelpers.Encoder.GetBytes("HTTP/1.1 101 Switching Protocols\r\nConnection:Upgrade\r\nUpgrade:websocket\r\nSec-WebSocket-Accept:");
     HandshakePatternB = StreamHelpers.Encoder.GetBytes("\r\n\r\n");
 }
示例#24
0
 /// <summary>
 /// CheckSum160 method implementation
 /// </summary>
 public static byte[] CheckSum160(string value)
 {
     byte[] hash = null;
     using (System.Security.Cryptography.SHA1 sha1 = System.Security.Cryptography.SHA1Cng.Create())
     {
         hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(value));
     }
     return(hash);
 }
        public static byte[] GenerateOtp(string appKey, string userKey, string challenge, OtpAlgorithmEnum AuthAlgorithm)
        {
            byte[] uKey  = Encoding.UTF8.GetBytes(userKey);
            byte[] aKey  = Encoding.UTF8.GetBytes(appKey);
            byte[] chall = Encoding.UTF8.GetBytes(challenge);

            byte[] inBuf = new byte[uKey.Length + aKey.Length + chall.Length];

            int j = 0;

            for (int i = 0; i < uKey.Length; i++)
            {
                inBuf[j++] = uKey[i];
            }

            for (int i = 0; i < aKey.Length; i++)
            {
                inBuf[j++] = aKey[i];
            }

            for (int i = 0; i < chall.Length; i++)
            {
                inBuf[j++] = chall[i];
            }

            byte[] hashedvalue = null;
            switch (AuthAlgorithm)
            {
            case OtpAlgorithmEnum.Md5:
                System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
                hashedvalue = md5.ComputeHash(inBuf);
                break;

            case OtpAlgorithmEnum.Sha1:
                System.Security.Cryptography.SHA1 sha1 = System.Security.Cryptography.SHA1.Create();
                hashedvalue = sha1.ComputeHash(inBuf);
                break;

            case OtpAlgorithmEnum.Des:
                int lenAdj = inBuf.Length % 8;
                if (lenAdj != 0)
                {
                    lenAdj = 8 - lenAdj;
                }
                //int byteLen =
                byte[] temp = new byte[inBuf.Length + lenAdj];
                Array.Copy(inBuf, temp, inBuf.Length);
                for (int i = 0; i < lenAdj; i++)
                {
                    temp[inBuf.Length + i] = 0x00;
                }

                hashedvalue = Encrypt3DES(new MemoryStream(temp), uKey, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }).ToArray();
                break;
            }
            return(hashedvalue);
        }
示例#26
0
        public static string doHash(string passwordPlain, string salt)
        {
            System.Security.Cryptography.SHA1 sha = System.Security.Cryptography.SHA1.Create();
            byte[] preHash  = System.Text.Encoding.UTF32.GetBytes(passwordPlain + salt);
            byte[] hash     = sha.ComputeHash(preHash);
            string password = System.Convert.ToBase64String(hash, 0, hash.Length);

            return(password);
        }
示例#27
0
        public override string Hash(BufferedStream stream)
        {
            byte[] checksum = null;
            System.Security.Cryptography.SHA1 sha = System.Security.Cryptography.SHA1.Create();
            checksum = sha.ComputeHash(stream);
            string hashResult = BitConverter.ToString(checksum).Replace("-", String.Empty);

            return(hashResult);
        }
示例#28
0
 /// <summary>
 /// CheckSum160 method implementation
 /// </summary>
 public static byte[] CheckSum160(byte[] value)
 {
     byte[] hash = null;
     using (System.Security.Cryptography.SHA1 sha1 = System.Security.Cryptography.SHA1Cng.Create())
     {
         hash = sha1.ComputeHash(value);
     }
     return(hash);
 }
示例#29
0
        public static Hash Compute(Stream contentStream)
        {
            System.Security.Cryptography.SHA1 hashAlgorithm = System.Security.Cryptography.SHA1.Create();
            long position = contentStream.Position;

            byte[] hashData = hashAlgorithm.ComputeHash(contentStream);
            contentStream.Position = position;

            return(new Hash(hashData));
        }
示例#30
0
        /// <summary>
        /// take any string and encrypt it using SHA1 then
        /// return the encrypted data
        /// </summary>
        /// <param name="data">input text you will enterd to encrypt it</param>
        /// <returns>return the encrypted text as hexadecimal string</returns>
        public static string GetSHA1HashData(string data)
        {
            System.Security.Cryptography.SHA1 hash    = System.Security.Cryptography.SHA1.Create();
            System.Text.ASCIIEncoding         encoder = new System.Text.ASCIIEncoding();
            byte[] combined = encoder.GetBytes(data);
            hash.ComputeHash(combined);
            string rethash = Convert.ToBase64String(hash.Hash);

            return(rethash);
        }
示例#31
0
 public TokenManager()
 {
     sha1 = HashAlgoFactory.Create<SHA1>();
     random = new RNGCryptoServiceProvider ();
     LastSecretGeneration = DateTime.MinValue; //in order to force the update
     secret = new byte[10];
     previousSecret = new byte[10];
     random.GetNonZeroBytes(secret);
     random.GetNonZeroBytes(previousSecret);
 }
示例#32
0
 public TokenManager()
 {
     sha1 = SHA1.Create();
     random = RandomNumberGenerator.Create();
     LastSecretGeneration = DateTime.MinValue; //in order to force the update
     secret = new byte[10];
     previousSecret = new byte[10];
     random.GetNonZeroBytes(secret);
     random.GetNonZeroBytes(previousSecret);
 }
示例#33
0
        private string savePath; // The path where the base directory will be put

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Creates a new FileManager with the supplied FileAccess
        /// </summary>
        /// <param name="files">The TorrentFiles you want to create/open on the disk</param>
        /// <param name="baseDirectory">The name of the directory that the files are contained in</param>
        /// <param name="savePath">The path to the directory that contains the baseDirectory</param>
        /// <param name="pieceLength">The length of a "piece" for this file</param>
        /// <param name="fileAccess">The access level for the files</param>
        internal FileManager(TorrentManager manager, TorrentFile[] files, int pieceLength, string savePath, string baseDirectory)
        {
            this.hasher = SHA1.Create();
            this.manager = manager;
            this.savePath = Path.Combine(savePath, baseDirectory);
            this.files = files;
            this.pieceLength = pieceLength;

            foreach (TorrentFile file in files)
                fileSize += file.Length;
        }
示例#34
0
    /// <summary>
    /// This function is used for encryption.
    /// </summary>
    /// <param name="strCode">The code.</param>
    /// <returns>string</returns>
    public static string Sha1Hash(string strCode)
    {
        string rehash = "";

        System.Security.Cryptography.SHA1 hash    = System.Security.Cryptography.SHA1.Create();
        System.Text.ASCIIEncoding         encoder = new System.Text.ASCIIEncoding();
        byte[] combined = encoder.GetBytes(strCode);
        hash.ComputeHash(combined);
        rehash = Convert.ToBase64String(hash.Hash);
        return(rehash);
    }
示例#35
0
	public HMACSHA1(byte[] rgbKey)
			{
				HashSizeValue = 160;
				if(rgbKey == null)
				{
					throw new ArgumentNullException("rgbKey");
				}
				SetKey(rgbKey);
				alg = null;
				algName = CryptoConfig.SHA1Default;
			}
		public void FixtureSetUp () 
		{
			Assembly a = Assembly.GetExecutingAssembly ();
			hashEvidence = new Hash (a);

			md5 = MD5.Create ();
			digestMd5 = hashEvidence.GenerateHash (md5);

			sha1 = SHA1.Create ();
			digestSha1 = hashEvidence.GenerateHash (sha1);
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <param name="encoding"></param>
        public SHA1TextReader(TextReader input, Encoding encoding)
            : base()
        {
            this.input = input;
            this.encoder = encoding.GetEncoder();

            this.sha1 = SHA1.Create();

            this.ibuf = new char[bufferSize];
            this.obuf = new byte[bufferSize];
            this.ibufIndex = 0;
        }
示例#38
0
        /// <summary>返回sha1算法小写字符串</summary>
        /// <param name="Text"></param>
        /// <returns></returns>
        public static string SHA1(string Text)
        {
            StringBuilder _result = new StringBuilder();

            System.Security.Cryptography.SHA1 sha1 = System.Security.Cryptography.SHA1.Create();
            byte[] sha1Arr = sha1.ComputeHash(Encoding.UTF8.GetBytes(Text));
            foreach (var b in sha1Arr)
            {
                _result.AppendFormat("{0:x2}", b);
            }
            return(_result.ToString().ToLower());
        }
示例#39
0
        public static string GetSwcSH1(string Password)
        {
            System.Security.Cryptography.SHA1 algorithm = SHA1.Create();
            byte[] data = algorithm.ComputeHash(Encoding.UTF8.GetBytes(Password));
            string sh1  = "";

            for (int i = 0; i < data.Length; i++)
            {
                sh1 += data[i].ToString("x2").ToUpperInvariant();
            }
            return(sh1);
        }
示例#40
0
        public static string SHA1(string orgStr)
        {
            string strResult = "";

            System.Security.Cryptography.SHA1 sha = System.Security.Cryptography.SHA1.Create();
            byte[] bytResult = sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(orgStr));
            for (int i = 0; i < bytResult.Length; i++)
            {
                strResult = strResult + bytResult[i].ToString("x2");
            }
            return(strResult);
        }
示例#41
0
        public override string StringHashAlgorithm(string value)
        {
            System.Security.Cryptography.SHA1 sha1 = System.Security.Cryptography.SHA1.Create();
            byte[]        bytes = sha1.ComputeHash(System.Text.ASCIIEncoding.UTF8.GetBytes(value));
            StringBuilder sb    = new StringBuilder();

            foreach (var b in bytes)
            {
                sb.Append(b.ToString("x2"));
            }
            return(sb.ToString());
        }
示例#42
0
 public static byte[] Sha1(byte[] text)
 {
     lock (sha1Lock)
     {
         if (sha1Alg == null)
         {
             sha1Alg = SHA1.Create();
         }
         sha1Alg.Initialize();
         return sha1Alg.ComputeHash(text);
     }
 }
示例#43
0
    string GetSha1(string input)
    {
        System.Security.Cryptography.SHA1 sha1Hash = System.Security.Cryptography.SHA1.Create();
        StringBuilder sBuilder = new StringBuilder();

        byte[] data = sha1Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
        for (int i = 0; i < data.Length; i++)
        {
            sBuilder.Append(data[i].ToString("x2"));
        }
        return(sBuilder.ToString());
    }
示例#44
0
        /// <summary>
        /// Mixes password and salt and hashes them
        /// </summary>
        /// <param name="password">The password.</param>
        /// <param name="salt">The salt.</param>
        /// <returns>Hashed Password string</returns>
        public static string CreatePasswordHash(string password, string salt)
        {
            string saltAndPwd = "mixing" + password + "with some" + salt;

            System.Security.Cryptography.SHA1 hash    = System.Security.Cryptography.SHA1.Create();
            System.Text.UTF8Encoding          encoder = new System.Text.UTF8Encoding();
            byte[] combined = encoder.GetBytes(saltAndPwd);
            hash.ComputeHash(combined);
            string hashCode = Convert.ToBase64String(hash.Hash);

            return(hashCode);
        }
示例#45
0
        private string GetSHA1HashData(string data)
        {
            System.Security.Cryptography.SHA1 sha1 = System.Security.Cryptography.SHA1.Create();
            byte[]        hashData    = sha1.ComputeHash(ASCIIEncoding.Default.GetBytes(data));
            StringBuilder returnValue = new StringBuilder();

            for (int i = 0; i < hashData.Length; i++)
            {
                returnValue.Append(hashData[i].ToString());
            }
            return(returnValue.ToString());
        }
示例#46
0
        /// <summary>
        /// Returns a SHA1 hash of the value formed by appending the GUID {0916C8E3-3431-4586-AF77-44BD3B16F961}
        /// to the value of msDS-UpdateScript of Partitions container.
        /// </summary>
        public static byte[] PrepareScriptHashSignature(string updateScript)
        {
            byte[] unicodeBytes = System.Text.Encoding.Unicode.GetBytes(updateScript);
            System.Security.Cryptography.SHA1 sha = System.Security.Cryptography.SHA1CryptoServiceProvider.Create();
            Guid        g           = new Guid("0916C8E3-3431-4586-AF77-44BD3B16F961");
            List <byte> rawByteList = new List <byte>();

            rawByteList.AddRange(unicodeBytes);
            rawByteList.AddRange(g.ToByteArray());

            byte[] hash1 = sha.ComputeHash(rawByteList.ToArray());
            return(hash1);
        }
示例#47
0
	public void FIPS186_Test1 (SHA1 hash) 
	{
		string className = hash.ToString ();
		byte[] result = { 0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, 0x6a, 0xba, 0x3e, 0x25, 0x71, 0x78, 0x50, 0xc2, 0x6c, 0x9c, 0xd0, 0xd8, 0x9d };
		byte[] input = Encoding.Default.GetBytes (input1);
		
		string testName = className + " 1";
		FIPS186_a (testName, hash, input, result);
		FIPS186_b (testName, hash, input, result);
		FIPS186_c (testName, hash, input, result);
		FIPS186_d (testName, hash, input, result);
		FIPS186_e (testName, hash, input, result);
	}
示例#48
0
	public void FIPS186_Test2 (SHA1 hash) 
	{
		string className = hash.ToString ();
		byte[] result = { 0x84, 0x98, 0x3e, 0x44, 0x1c, 0x3b, 0xd2, 0x6e, 0xba, 0xae, 0x4a, 0xa1, 0xf9, 0x51, 0x29, 0xe5, 0xe5, 0x46, 0x70, 0xf1 };
		byte[] input = Encoding.Default.GetBytes (input2);
		
		string testName = className + " 2";
		FIPS186_a (testName, hash, input, result);
		FIPS186_b (testName, hash, input, result);
		FIPS186_c (testName, hash, input, result);
		FIPS186_d (testName, hash, input, result);
		FIPS186_e (testName, hash, input, result);
	}
示例#49
0
    private static string GetHashString(string unhashed)
    {
        byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(unhashed);
        System.Security.Cryptography.SHA1 sha = System.Security.Cryptography.SHA1.Create();
        byte[] hash = sha.ComputeHash(inputBytes);
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        for (int i = 0; i < hash.Length; i++)
        {
            sb.Append(hash[i].ToString("x2"));
        }

        return(sb.ToString());
    }
示例#50
0
        private static Sha1 HashImpl(crypt.SHA1 alg, ReadOnlySpan <byte> span)
        {
            Debug.Assert(alg != null);

            // Do NOT short-circuit here; rely on call-sites to do so
#if !NETSTANDARD2_0
            Span <byte> hash = stackalloc byte[Sha1.ByteLength];
            alg.TryComputeHash(span, hash, out _);
#else
            var hash = alg.ComputeHash(span.ToArray());
#endif
            var sha = new Sha1(hash);
            return(sha);
        }
示例#51
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposing && !isDisposed)
            {
                sha.Clear();
                sha = null;

                certsComplete = null;
                certCa = null;
                certCp = null;
                certXs = null;
            }

            isDisposed = true;
        }
示例#52
0
	public void FIPS186_Test3 (SHA1 hash) 
	{
		string className = hash.ToString ();
		byte[] result = { 0x34, 0xaa, 0x97, 0x3c, 0xd4, 0xc4, 0xda, 0xa4, 0xf6, 0x1e, 0xeb, 0x2b, 0xdb, 0xad, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6f };
		byte[] input = new byte [1000000];
		for (int i = 0; i < 1000000; i++)
			input[i] = 0x61; // a
		
		string testName = className + " 3";
		FIPS186_a (testName, hash, input, result);
		FIPS186_b (testName, hash, input, result);
		FIPS186_c (testName, hash, input, result);
		FIPS186_d (testName, hash, input, result);
		FIPS186_e (testName, hash, input, result);
	}
示例#53
0
        // sha1 below
        public static string GetSHA1Hash(string str)
        {
            System.Security.Cryptography.SHA1 sha1 = System.Security.Cryptography.SHA1.Create();
            byte[] bytes   = Encoding.Default.GetBytes(str);
            byte[] encoded = sha1.ComputeHash(bytes);

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < encoded.Length; i++)
            {
                sb.Append(encoded[i].ToString("x2"));
            }

            return(sb.ToString());
        }
示例#54
0
        public async Task<Stream> OpenStreamAsync()
        {
            SqlParameter idParam;
            using (SqlCommand cmdInsert = this.CreateInsertCmd(out idParam))
            {
                await cmdInsert.ExecuteNonQueryAsync();

                this.id = (int)idParam.Value;

                BlobWriteStream blobStream = new BlobWriteStream(this.connection, null, "dbo", "Blobs", "Content", "BlobId", this.id);

                this.sha1 = new SHA1Managed();
                this.stream = new CryptoStream(blobStream, this.sha1, CryptoStreamMode.Write);

                return this.stream;
            }
        }
        /// <summary>
        ///  验证面md5值是否先等
        /// </summary>
        /// <param name="md5Hash"></param>
        /// <param name="input"></param>
        /// <param name="hash"></param>
        /// <returns></returns>
        private static bool VerifySHA1Hash(SHA1 SHA1Hash, string input, string hash)
        {
            // Hash the input.
            string hashOfInput = GetSHA1Hash(SHA1Hash, input);

            // Create a StringComparer an compare the hashes.
            StringComparer comparer = StringComparer.OrdinalIgnoreCase;

            if (0 == comparer.Compare(hashOfInput, hash))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
示例#56
0
 public Coinichiwa(cDiceBot Parent)
 {
     this.Parent = Parent;
     Hasher = SHA1.Create();
     maxRoll = 99.99;
     AutoInvest = false;
     AutoWithdraw = false;
     ChangeSeed = false;
     AutoLogin = true;
     BetURL="https://www.coinichiwa.com/a/2947221";
     Name = "Coinichiwa";
     Tip = false;
     SiteURL = "https://www.coinichiwa.com/a/2947221";
     register = false;
     System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(GetBalanceThread));
     t.Start();
 }
示例#57
0
        static CrpytoHelperFile()
        {
            sha = new SHA1CryptoServiceProvider();
            var cryptoService = new TripleDESCryptoServiceProvider();

            byte[] cryptoKey =
                {
                    136, 183, 142, 217, 175, 71, 90, 239, 99, 107, 3, 17, 47, 199, 243, 127, 97, 173, 141,
                    87, 59, 22, 200, 179
                };
            byte[] cryptoIV = { 227, 105, 5, 40, 162, 158, 143, 156 };

            cryptoService.Key = cryptoKey;
            cryptoService.IV = cryptoIV;

            et = cryptoService.CreateEncryptor();
            dt = cryptoService.CreateDecryptor();
        }
示例#58
0
文件: EditAccount.cs 项目: ltj/rentit
        // get sha1 hash as string from string
        private static string GetSha1Hash(SHA1 sha1Hash, string input)
        {
            // Convert the input string to a byte array and compute the hash.
            byte[] data = sha1Hash.ComputeHash(Encoding.UTF8.GetBytes(input));

            // Create a new Stringbuilder to collect the bytes
            // and create a string.
            StringBuilder sBuilder = new StringBuilder();

            // Loop through each byte of the hashed data
            // and format each one as a hexadecimal string.
            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }

            // Return the hexadecimal string.
            return sBuilder.ToString();
        }
示例#59
0
        public SRP6()
        {
            Sha1 = new SHA1Managed();

            N = new byte[]
            {
                0x89, 0x4B, 0x64, 0x5E, 0x89, 0xE1, 0x53, 0x5B, 0xBD, 0xAD, 0x5B, 0x8B, 0x29, 0x06, 0x50, 0x53,
                0x08, 0x01, 0xB1, 0x8E, 0xBF, 0xBF, 0x5E, 0x8F, 0xAB, 0x3C, 0x82, 0x87, 0x2A, 0x3E, 0x9B, 0xB7,
            };

            Salt = new byte[]
            {
                0xAD, 0xD0, 0x3A, 0x31, 0xD2, 0x71, 0x14, 0x46, 0x75, 0xF2, 0x70, 0x7E, 0x50, 0x26, 0xB6, 0xD2,
                0xF1, 0x86, 0x59, 0x99, 0x76, 0x02, 0x50, 0xAA, 0xB9, 0x45, 0xE0, 0x9E, 0xDD, 0x2A, 0xA3, 0x45
            };

            BN = MakeBigInteger(N);
            g = MakeBigInteger(new byte[] { 7 });
            k = MakeBigInteger(new byte[] { 3 });
        }
示例#60
0
 //clientServer: true if random bytes should be processed as first the client bytes, then the server bytes
 //              false otherwise
 public Ssl3DeriveBytes(byte[] secret, byte[] clientRandom, byte[] serverRandom, bool clientServer)
 {
     if (secret == null || clientRandom == null || serverRandom == null)
         throw new ArgumentNullException();
     if (clientRandom.Length != 32 || serverRandom.Length != 32)
         throw new ArgumentException();
     m_Disposed = false;
     m_Secret = (byte[])secret.Clone();
     m_Random = new byte[64];
     if (clientServer) {
         Array.Copy(clientRandom, 0, m_Random, 0, 32);
         Array.Copy(serverRandom, 0, m_Random, 32, 32);
     } else {
         Array.Copy(serverRandom, 0, m_Random, 0, 32);
         Array.Copy(clientRandom, 0, m_Random, 32, 32);
     }
     m_MD5 = new MD5CryptoServiceProvider();
     m_SHA1 = new SHA1CryptoServiceProvider();
     Reset();
 }