コード例 #1
0
ファイル: HashModule.cs プロジェクト: GruntTheDivine/Iodine
		private IodineObject sha256 (VirtualMachine vm, IodineObject self, IodineObject[] args)
		{
			if (args.Length <= 0) {
				vm.RaiseException (new IodineArgumentException (1));
				return null;
			}

			byte[] bytes = new byte[]{};
			byte[] hash = null;

			SHA256Managed hashstring = new SHA256Managed();

			if (args[0] is IodineString) {
				bytes = System.Text.Encoding.UTF8.GetBytes (args[0].ToString ());
				hash = hashstring.ComputeHash(bytes);
			} else if (args[0] is IodineByteArray) {
				bytes = ((IodineByteArray)args[0]).Array;
				hash = hashstring.ComputeHash(bytes);
			} else if (args[0] is IodineStream) {
				hash = hashstring.ComputeHash(((IodineStream)args[0]).File);
			} else {
				vm.RaiseException (new IodineTypeException ("Str"));
				return null;
			}

			return new IodineByteArray (hash);
		}
コード例 #2
0
        public static CompareResult Compare(Bitmap bmp1, Bitmap bmp2)
        {
            CompareResult cr = CompareResult.ciCompareOk;

            //Test to see if we have the same size of image
            if (bmp1.Size != bmp2.Size)
            {
                cr = CompareResult.ciSizeMismatch;
            }
            else
            {
                //Convert each image to a byte array
                System.Drawing.ImageConverter ic =
                       new System.Drawing.ImageConverter();
                byte[] btImage1 = new byte[1];
                btImage1 = (byte[])ic.ConvertTo(bmp1, btImage1.GetType());
                byte[] btImage2 = new byte[1];
                btImage2 = (byte[])ic.ConvertTo(bmp2, btImage2.GetType());

                //Compute a hash for each image
                SHA256Managed shaM = new SHA256Managed();
                byte[] hash1 = shaM.ComputeHash(btImage1);
                byte[] hash2 = shaM.ComputeHash(btImage2);

                //Compare the hash values
                for (int i = 0; i < hash1.Length && i < hash2.Length
                                  && cr == CompareResult.ciCompareOk; i++)
                {
                    if (hash1[i] != hash2[i])
                        cr = CompareResult.ciPixelMismatch;
                }
            }
            return cr;
        }
コード例 #3
0
ファイル: Sha256Tests.cs プロジェクト: jrick/Paymetheus
        public static void DoubleSha256Test()
        {
            var innerExpected = new byte[] {
                0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
                0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
                0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
                0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad,
            };
            var vector = Encoding.ASCII.GetBytes("abc");
            var hasher = new SHA256Managed();
            var innerDigest = hasher.ComputeHash(vector);

            Assert.Equal(innerDigest, innerExpected);

            var outerExpected = new byte[] {
                0x4f, 0x8b, 0x42, 0xc2, 0x2d, 0xd3, 0x72, 0x9b,
                0x51, 0x9b, 0xa6, 0xf6, 0x8d, 0x2d, 0xa7, 0xcc,
                0x5b, 0x2d, 0x60, 0x6d, 0x05, 0xda, 0xed, 0x5a,
                0xd5, 0x12, 0x8c, 0xc0, 0x3e, 0x6c, 0x63, 0x58,
            };
            var outerDigest = hasher.ComputeHash(innerDigest);

            Assert.Equal(outerDigest, outerExpected);

            Assert.Equal(outerDigest, WalletSeed.DoubleSha256(vector));
        }
コード例 #4
0
ファイル: KoboMasterKeys.cs プロジェクト: 13xforever/DeDRM
        private static readonly string[] Salts = { "QJhwzAtXL", "XzUhGYdFp", "NoCanLook" }; //lol, new salt isn't really being used

        #endregion Fields

        #region Methods

        public static List<byte[]> Retrieve(SQLiteConnection connection)
        {
            using (var sha256 = new SHA256Managed())
            {
                var combinedSalt = Salts[1] + Salts[2]; //XzUhGYdFpNoCanLook
                var combinedHash = sha256.ComputeHash(Encoding.ASCII.GetBytes(combinedSalt)).ToHexString(); //8bd007187bc88b3a2e1371b6f5f4fa0719f8b45104841b382b18e671f8ba2057
                var realSalt = combinedHash.Substring(11, 9); //88b3a2e13
                var macs = NetworkInterface.GetAllNetworkInterfaces()
                    .Where(iface => iface.NetworkInterfaceType != NetworkInterfaceType.Loopback)
                    .Select(iface => iface.GetPhysicalAddress().ToMacString())
                    .Distinct()
                    .Where(addr => !string.IsNullOrEmpty(addr))
                    .ToList();
                var secrets = macs.Select(mac => realSalt + mac).ToList(); //88b3a2e13FF:FF:FF:FF:FF:FF //should select first active ethernet adapter
                var deviceIds = secrets.Select(secret => sha256.ComputeHash(Encoding.ASCII.GetBytes(secret)).ToHexString()).ToList();

                var userIds = new List<string>();
                using (var cmd = new SQLiteCommand("select UserID from user", connection))
                using (var reader = cmd.ExecuteReader())
                    while (reader.Read())
                        userIds.Add(reader["UserID"] as string);

                var result = (
                    from userId in userIds
                    from deviceId in deviceIds
                    select Encoding.UTF8.GetBytes((deviceId + userId).Trim()) into key
                    select sha256.ComputeHash(key) into hash
                    select hash.Copy(hash.Length - 16)
                ).ToList();

                //var strResult = result.Select(b => b.ToHexString()).Distinct().ToList();
                return result;
            }
        }
コード例 #5
0
 public static String FromByteArray(Byte[] b, Byte version)
 {
     SHA256 sha256 = new SHA256Managed();
     b = (new Byte[] { version }).Concat(b).ToArray();
     Byte[] hash = sha256.ComputeHash(sha256.ComputeHash(b)).Take(4).ToArray();
     return Base58String.FromByteArray(b.Concat(hash).ToArray());
 }
コード例 #6
0
ファイル: WalletSeed.cs プロジェクト: decred/Paymetheus
 // Returned array contains the double SHA256 hash.
 public static byte[] DoubleSha256(byte[] value)
 {
     using (var hasher = new SHA256Managed())
     {
         var intermediateHash = hasher.ComputeHash(value);
         return hasher.ComputeHash(intermediateHash);
     }
 }
コード例 #7
0
ファイル: PrivateKey.cs プロジェクト: ystallonne/Bitcoin-Tool
 public static PrivateKey FromMiniKey(String s)
 {
     SHA256 sha256 = new SHA256Managed();
     Byte[] b = Encoding.ASCII.GetBytes(s);
     if (sha256.ComputeHash(b.Concat(new Byte[] { (Byte)'?' }).ToArray()).First() != 0x00)
         throw new ArgumentException("Invalid miniKey");
     return new PrivateKey(sha256.ComputeHash(b));
 }
コード例 #8
0
ファイル: Utils.cs プロジェクト: nuggetbram/CoiniumServ
 /// <summary>
 /// Calculates SHA256(SHA256(byte range 1 + byte range 2)).
 /// </summary>
 public static byte[] DoubleDigestTwoBuffers(byte[] input1, int offset1, int length1, byte[] input2, int offset2, int length2)
 {
     var algorithm = new SHA256Managed();
     var buffer = new byte[length1 + length2];
     Array.Copy(input1, offset1, buffer, 0, length1);
     Array.Copy(input2, offset2, buffer, length1, length2);
     var first = algorithm.ComputeHash(buffer, 0, buffer.Length);
     return algorithm.ComputeHash(first);
 }
コード例 #9
0
 public static byte[] Hash(byte[] bytes, int offset, int count)
 {
     using (var x = new SHA256Managed())
     {
         var hash1 = x.ComputeHash(bytes, offset, count);
         var hash2 = x.ComputeHash(hash1);
         return hash2;
     }
 }
コード例 #10
0
 public static Byte[] ToByteArray(String s, out Byte version)
 {
     SHA256 sha256 = new SHA256Managed();
     Byte[] b = Base58String.ToByteArray(s);
     Byte[] hash = sha256.ComputeHash(sha256.ComputeHash(b.Take(b.Length - 4).ToArray()));
     if (!hash.Take(4).SequenceEqual(b.Skip(b.Length - 4).Take(4)))
         throw new ArgumentException("Invalid Base58Check String");
     version = b.First();
     return b.Skip(1).Take(b.Length - 5).ToArray();
 }
コード例 #11
0
ファイル: Message.cs プロジェクト: ystallonne/Bitcoin-Tool
 public Message(String command, IPayload payload, bool TestNet = false)
 {
     SHA256 sha256 = new SHA256Managed();
     Byte[] payloadBytes = payload.ToBytes();
     if (!TestNet)
         this.magic = 0xD9B4BEF9;
     else
         this.magic = 0x0709110B;
     this.command = Encoding.ASCII.GetBytes(command).Concat(new Byte[12 - command.Length]).ToArray();
     this.length = (UInt32)payloadBytes.Length;
     this.checksum = sha256.ComputeHash(sha256.ComputeHash(payloadBytes)).Take(4).ToArray();
     this.payload = payload;
 }
コード例 #12
0
 public static string GetHash(string secretKey,string date, string body)
 {
     byte[] hashArray;
     using (var encryptor = new SHA256Managed())
     {
         var payloadByteArray = Encoding.UTF8.GetBytes(string.Concat(secretKey,secretKey));
         var payload = string.Concat(Convert.ToBase64String(encryptor.ComputeHash(payloadByteArray)), date, body);
         payloadByteArray = Encoding.UTF8.GetBytes(payload);
         hashArray = encryptor.ComputeHash(payloadByteArray);
     }
     var hash = Convert.ToBase64String(hashArray);
     return hash;
 }
コード例 #13
0
ファイル: HashMax.cs プロジェクト: maxrev17/docstore
        public string HashFile(string path)
        {
            try
            {
                var fi = new FileInfo(path);
                byte[] bytes = new byte[3072];
                string raw = "";
                string hash = "";
                var sha256 = new SHA256Managed();

                FileStream fs = System.IO.File.OpenRead(path);

                if (fi.Length > 3072)
                {
                    long middle = (long)Math.Floor((double)fi.Length / (double)2);
                    long last = fi.Length - 1024;

                    fs.Seek(0, SeekOrigin.Begin);
                    fs.Read(bytes, 0, 1024);
                    fs.Seek(middle, SeekOrigin.Current);
                    fs.Read(bytes, 1024, 1024);
                    fs.Seek(last, SeekOrigin.Current);
                    fs.Read(bytes, 2048, 1024);

                    raw = ByteToString(bytes);

                    hash = ByteToString(sha256.ComputeHash(Encoding.UTF8.GetBytes(raw))) + fi.Length.ToString();
                }
                else
                {
                    hash = ByteToString(sha256.ComputeHash(fs)) + fi.Length.ToString();
                }

                fs.Close();
                return hash;
            }
            catch (FileNotFoundException ex)
            {
                // file not found
                Logger.Write(ex.Message);
            }
            catch (IOException ex)
            {
                // file could not be accessed
                // warn user and try again on OK
                Logger.Write("Error, " + ex.Message);
            }
            return null;
        }
コード例 #14
0
 public static byte[] SHA256(string str)
 {
     byte[] SHA256Data = Encoding.UTF8.GetBytes(str);
     System.Security.Cryptography.SHA256Managed Sha256 = new System.Security.Cryptography.SHA256Managed();
     byte[] by = Sha256.ComputeHash(SHA256Data);
     return(by);
 }
コード例 #15
0
 public static string SHA256(string strToHash)
 {
     System.Security.Cryptography.SHA256Managed sha256Obj = new System.Security.Cryptography.SHA256Managed();
     byte[] bytesToHash = System.Text.Encoding.UTF8.GetBytes(strToHash);
     bytesToHash = sha256Obj.ComputeHash(bytesToHash);
     return(BitConverter.ToString(bytesToHash).Replace("-", "").ToUpper());
 }
コード例 #16
0
ファイル: Sha.cs プロジェクト: 0xdeafcafe/FapChat
 /// <summary>
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public static string Sha256(string data)
 {
     byte[] bytes = Encoding.UTF8.GetBytes(data);
     var hashstring = new SHA256Managed();
     byte[] hash = hashstring.ComputeHash(bytes);
     return hash.Aggregate(string.Empty, (current, x) => current + String.Format("{0:x2}", x));
 }
コード例 #17
0
        protected virtual string GetBundleVirtualPath(string prefix, string postfix, string[] parts)
        {
            if (parts == null || parts.Length == 0)
                throw new ArgumentException("parts");

            //calculate hash
            var hash = "";
            using (SHA256 sha = new SHA256Managed())
            {
                // string concatenation
                var hashInput = "";
                foreach (var part in parts)
                {
                    hashInput += part;
                    hashInput += ",";
                }

                byte[] input = sha.ComputeHash(Encoding.Unicode.GetBytes(hashInput));
                hash = HttpServerUtility.UrlTokenEncode(input);
            }
            //ensure only valid chars
            hash = SeoExtensions.GetSeName(hash);

            var sb = new StringBuilder(prefix);
            sb.Append(hash);
            sb.Append(postfix);
            return sb.ToString();
        }
コード例 #18
0
ファイル: Hash.cs プロジェクト: sczk/collab-project
 public static string Sha256(string password)
 {
     SHA256Managed crypt = new SHA256Managed();
     string hash = String.Empty;
     byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(password), 0, Encoding.UTF8.GetByteCount(password));
     return crypto.Aggregate(hash, (current, bit) => current + bit.ToString("x2"));
 }
コード例 #19
0
        public override string Encrypt(string data)
        {
            SHA256Managed sha256hasher = new SHA256Managed();

            try
            {
                UTF8Encoding encoder = new UTF8Encoding();

                byte[] hashedDataBytes = sha256hasher.ComputeHash(encoder.GetBytes(string.Format(base.hashFormat, data)));

                return Convert.ToBase64String(hashedDataBytes);
            }
            catch (Exception e)
            {
                var exception = new CryptologyException("SHA256Encryptor.Encrypt()", "An error occurred while encrypting.", e);
                exception.Data.Add("hashFormat", hashFormat);
                exception.Data.Add("data", data);

                throw exception;
            }
            finally
            {
                sha256hasher.Dispose();
            }
        }
コード例 #20
0
 public static string SHA256(string str)
 {
     byte[] bytes = System.Text.Encoding.UTF8.GetBytes(str);
     System.Security.Cryptography.SHA256Managed sHA256Managed = new System.Security.Cryptography.SHA256Managed();
     byte[] inArray = sHA256Managed.ComputeHash(bytes);
     return(System.Convert.ToBase64String(inArray));
 }
コード例 #21
0
ファイル: Utils.cs プロジェクト: ekople/VR2
        public static string GenerateSaltedHash(string userName, string pssWd)
        {
            if (userName ==null || pssWd == null)
            {
                return null;
            }
            byte[] userNameBytes = GetBytes(userName);
            byte[] pssWdBytes = GetBytes(pssWd);
            HashAlgorithm algorithm = new SHA256Managed();

            byte[] plainTextWithSaltBytes =
              new byte[userNameBytes.Length + pssWdBytes.Length];

            for (int i = 0; i < userNameBytes.Length; i++)
            {
                plainTextWithSaltBytes[i] = userNameBytes[i];
            }
            for (int i = 0; i < pssWdBytes.Length; i++)
            {
                plainTextWithSaltBytes[userNameBytes.Length + i] = pssWdBytes[i];
            }

            byte[] hash = algorithm.ComputeHash(plainTextWithSaltBytes);
            StringBuilder sBuilder = new StringBuilder();

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

            return sBuilder.ToString();
        }
コード例 #22
0
 public static string sha256encrypt(string phrase)
 {
     UTF8Encoding encoder = new UTF8Encoding();
     SHA256Managed sha256hasher = new SHA256Managed();
     byte[] hashedDataBytes = sha256hasher.ComputeHash(encoder.GetBytes(phrase));
     return byteArrayToString(hashedDataBytes);
 }
コード例 #23
0
        public static string EncryptPassword(string password, byte[] salt)
        {
            // Convert the plain string pwd into bytes
            byte[] plainTextBytes = Encoding.UTF8.GetBytes(password);
            // Append salt to pwd before hashing
            byte[] combinedBytes = new byte[plainTextBytes.Length + salt.Length];
            System.Buffer.BlockCopy(plainTextBytes, 0, combinedBytes, 0, plainTextBytes.Length);
            System.Buffer.BlockCopy(salt, 0, combinedBytes, plainTextBytes.Length, salt.Length);

            // Create hash for the pwd+salt
            System.Security.Cryptography.HashAlgorithm hashAlgo = new System.Security.Cryptography.SHA256Managed();
            byte[] hash = hashAlgo.ComputeHash(combinedBytes);

            var hashString = GetString(hash);
            var saltString = GetString(salt);

            var passwordHash = string.IsNullOrWhiteSpace(saltString) ? hashString : $"{hashString}.{saltString}";

            var hashBytes   = GetBytes(hashString).ToArray();
            var hashString2 = GetString(hashBytes);

            if (hashString != hashString2)
            {
                throw new SecurityException("Hashes are not equal. There is some bug.");
            }

            return(passwordHash);
        }
コード例 #24
0
ファイル: Cryptography.cs プロジェクト: codaxy/common
 public static String SHA256(String text)
 {
     UTF8Encoding encoder = new UTF8Encoding();
     SHA256Managed sha256hasher = new SHA256Managed();
     byte[] hashedDataBytes = sha256hasher.ComputeHash(encoder.GetBytes(text));
     return System.Convert.ToBase64String(hashedDataBytes);
 }
コード例 #25
0
        /// <summary>
        /// check user password
        /// </summary>
        /// <param name="password">submitted password</param>
        /// <returns>hashed password</returns>
        public string CheckUserPassword(string password)
        {
            //return FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5");

            //string salt = GenerateSalt();

            //start hash creation:
            System.Security.Cryptography.SHA256 sha256 = new System.Security.Cryptography.SHA256Managed();

            // password string to bytes
            byte[] sha256Bytes = System.Text.Encoding.UTF8.GetBytes(password);

            //password bytes to hash
            byte[] cryString = sha256.ComputeHash(sha256Bytes);

            // start final encrypted password
            string sha256Str = string.Empty;

            // create final encrypted password: bytes to hex string
            for (int i = 0; i < cryString.Length; i++)
            {
                sha256Str += cryString[i].ToString("X");
            }

            // concatenate hashed password + salt
            // sha256Str = sha256Str + salt;

            return(sha256Str);
        }
コード例 #26
0
        public string sha256encrypt(string phrase)
        {
            SHA256Managed sha256 = new SHA256Managed();
            byte[] hashedData = sha256.ComputeHash(encoder.GetBytes(phrase));

            return byteArrayToString(hashedData);
        }
コード例 #27
0
        //pass in entered PW as parameter; hashes it and compared to stored PW
        public bool comparePW(string enteredPW)//returns true if match; false if not
        {
            bool ret;

            if (IsHashed == false)
            {
                hashPW();
            }

            using (var sha = new System.Security.Cryptography.SHA256Managed())
            {
                byte[] textData = System.Text.Encoding.UTF8.GetBytes(enteredPW);
                byte[] hash     = sha.ComputeHash(textData);
                enteredPW = BitConverter.ToString(hash).Replace("-", String.Empty);
            }

            if (enteredPW == PW)
            {
                ret = true;
            }
            else
            {
                ret = false;
            }


            return(ret);
        }
コード例 #28
0
        /// <summary>
        /// Encrypts the user's password
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public string EncryptUserPassword(string password)
        {
            //return FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5");

            string salt = GenerateSalt();

            //start hash creation:
            System.Security.Cryptography.SHA256 sha256 = new System.Security.Cryptography.SHA256Managed();

            // password string to bytes
            byte[] sha256Bytes = System.Text.Encoding.UTF8.GetBytes(password);

            //password bytes to hash
            byte[] cryString = sha256.ComputeHash(sha256Bytes);

            // start final encrypted password
            string sha256Str = string.Empty;

            // create final encrypted password: bytes to hex string
            for (int i = 0; i < cryString.Length; i++)
            {
                sha256Str += cryString[i].ToString("X");
            }

            // concatenate hashed password + salt
            // sha256Str = sha256Str + salt;

            return sha256Str;
        }
コード例 #29
0
 public static string Sha256Hash(byte[] ba)
 { 
     SHA256Managed sha2 = new SHA256Managed();
     byte[] ba2 = sha2.ComputeHash(ba);
     sha2 = null;
     return BitConverter.ToString(ba2).Replace("-", string.Empty).ToLower();
 }
コード例 #30
0
 private string GetHash(string key)
 {
     using var sha = new System.Security.Cryptography.SHA256Managed();
     byte[] textData = System.Text.Encoding.UTF8.GetBytes(key);
     byte[] hash     = sha.ComputeHash(textData);
     return(BitConverter.ToString(hash).Replace("-", string.Empty));
 }
コード例 #31
0
ファイル: Encrypt.cs プロジェクト: lirongjun0926/Farseer.Net
 /// <summary>
 ///     SHA256º¯Êý
 /// </summary>
 /// ///
 /// <param name="str">ԭʼ×Ö·û´®</param>
 /// <returns>SHA256½á¹û</returns>
 public static string SHA256(string str)
 {
     var SHA256Data = Encoding.UTF8.GetBytes(str);
     var Sha256 = new SHA256Managed();
     var Result = Sha256.ComputeHash(SHA256Data);
     return Convert.ToBase64String(Result); //·µ»Ø³¤¶ÈΪ44×Ö½ÚµÄ×Ö·û´®
 }
コード例 #32
0
ファイル: DatasData.cs プロジェクト: ne-sachirou/yUsin-1
 protected string ComputeHashString(string rawString)
 {
     System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
     SHA256 hashM = new SHA256Managed();
     return encoding.GetString(hashM.ComputeHash(encoding.GetBytes(rawString))).
         Replace(',', '.').Replace('\r', '.').Replace('\n', '.');
 }
コード例 #33
0
        public static void ExecuteMongo()
        {
            const string connectionString = "mongodb://localhost";
            var client = new MongoClient(connectionString);
            var server = client.GetServer();
            var database = server.GetDatabase("Polyglot");
            var directory = database.GetCollection<RootDirectory>("rootdirectory");
            directory.Remove(new QueryDocument());

            byte[] inputBytes = System.Text.Encoding.Unicode.GetBytes("password");//will need to change to being the user input
            SHA256Managed hashstring = new SHA256Managed();
            byte[] dbHash = hashstring.ComputeHash(inputBytes);

            directory.Insert(new RootDirectory()
            {
                _id = ObjectId.GenerateNewId().ToString(),
                un = "harageth",
                pw = System.Text.Encoding.UTF8.GetString(dbHash),//need to encrypt this password
                folders = new List<Folder>() { new Folder() { folderName = "firstFolder", files = new List<string>() { "temp1.txt", "file1.txt" } }, new Folder() { folderName = "secondFolder", files = new List<string>() { "temp2.txt", "file2.txt" } }, new Folder() { folderName = "thirdFolder", files = new List<string>() { "temp3.txt", "file3.txt" } } },
                files = new List<string>( ) { "temp.txt", "file.txt" }

            });

            directory.Insert(new RootDirectory()
            {
                _id = ObjectId.GenerateNewId().ToString(),
                un = "Guest",
                //folders = new List<Folder>() { new Folder() { folderName = "firstFolder", files = new List<string>() { "temp1.txt", "file1.txt" } }, new Folder() { folderName = "secondFolder", files = new List<string>() { "temp2.txt", "file2.txt" } }, new Folder() { folderName = "thirdFolder", files = new List<string>() { "temp3.txt", "file3.txt" } } },
                //files = new List<string>() { "temp.txt", "file.txt" }

            });
        }
コード例 #34
0
        protected virtual string GetBundleVirtualPath(string prefix, string extension, string[] parts)
        {
            if (parts == null || parts.Length == 0)
                throw new ArgumentException("parts");

            //calculate hash
            var hash = "";
            using (SHA256 sha = new SHA256Managed())
            {
                // string concatenation
                var hashInput = "";
                foreach (var part in parts)
                {
                    hashInput += part;
                    hashInput += ",";
                }

                byte[] input = sha.ComputeHash(Encoding.Unicode.GetBytes(hashInput));
                hash = HttpServerUtility.UrlTokenEncode(input);
            }
            //ensure only valid chars
            hash = SeoExtensions.GetSeName(hash);

            var sb = new StringBuilder(prefix);
            sb.Append(hash);
            //we used "extension" when we had "runAllManagedModulesForAllRequests" set to "true" in web.config
            //now we disabled it. hence we should not use "extension"
            //sb.Append(extension);
            return sb.ToString();
        }
コード例 #35
0
ファイル: EncryptHelper.cs プロジェクト: robotbird/jqpress
 /// <summary>
 /// SHA256函数
 /// </summary>
 /// /// <param name="str">原始字符串</param>
 /// <returns>SHA256结果</returns>
 public static string SHA256(string str)
 {
     byte[] SHA256Data = Encoding.UTF8.GetBytes(str);
     SHA256Managed Sha256 = new SHA256Managed();
     byte[] Result = Sha256.ComputeHash(SHA256Data);
     return Convert.ToBase64String(Result);  //返回长度为44字节的字符串
 }
コード例 #36
0
ファイル: MainPage.xaml.cs プロジェクト: quad341/zpd
        // Taken from http://dotnetpulse.blogspot.com/2007/12/sha1-hash-calculation-in-c.html
        private static string Sha1HashOfString(string input)
        {
            byte[] buffer = Encoding.Unicode.GetBytes(input);
            var crypto = new SHA256Managed();

            return BitConverter.ToString(crypto.ComputeHash(buffer)).Replace("-", "");
        }
コード例 #37
0
 public ActionResult DevEditPost(DevEditViewModel editVm)
 {
     var repo = new Repository();
     var original = GetDevEditViewModel(editVm.Id);
     original.Message = editVm.Message;
     var asc = new WebClient().DownloadData(repo.GetASCLink(editVm.Id));
     string extracted;
     if(!CryptoHelper.VerifySig(asc, editVm.Message, out extracted))
     {
         ModelState.AddModelError("Message", "Incorrectly signed");
     }
     else
     {
         byte[] hash = null;
         using(SHA256 sha = new SHA256Managed())
         {
             hash = sha.ComputeHash(Encoding.UTF8.GetBytes(extracted));
         }
         if(repo.SaveHash(hash))
         {
             repo.UpdateDevViewModel(original);
             return RedirectToAction("Dev", "Main", new
             {
                 devId = editVm.Id
             });
         }
         else
         {
             ModelState.AddModelError("Message", "You can't replay an old message");
         }
     }
     return View("DevEdit", original);
 }
コード例 #38
0
 public static byte[] Sha256(string hashInput)
 {
     System.Security.Cryptography.SHA256 sha256 = new System.Security.Cryptography.SHA256Managed();
     byte[] hash;
     hash = Encoding.ASCII.GetBytes(hashInput);
     hash = sha256.ComputeHash(hash);
     return(hash);
 }
コード例 #39
0
        public static byte[] Sha256b(string input)
        {
            var crypt = new System.Security.Cryptography.SHA256Managed();
            var hash  = new System.Text.StringBuilder();

            byte[] crypto = crypt.ComputeHash(System.Text.Encoding.ASCII.GetBytes(input));
            return(crypto);
        }
コード例 #40
0
ファイル: mscEnCode.cs プロジェクト: ArjenCole/missions
         /// <summary>
         /// SHA256加密,不可逆转
         /// </summary>
         /// <param name="str">string str:被加密的字符串</param>
         /// <returns>返回加密后的字符串</returns>
         private static string SHA256Encrypt(string str)
 {
     System.Security.Cryptography.SHA256 s256 = new System.Security.Cryptography.SHA256Managed();
     byte[] byte1;
     byte1 = s256.ComputeHash(Encoding.Default.GetBytes(str));
     s256.Clear();
     return(Convert.ToBase64String(byte1));
 }
コード例 #41
0
        /// <summary>
        /// SHA256加密
        /// </summary>
        /// <param name="data">数据</param>
        /// <returns></returns>
        // ReSharper disable once InconsistentNaming
        public static string SHA256(string data)
        {
            var byteData = Encoding.UTF8.GetBytes(data);
            var sha256   = new SHA256Managed();
            var result   = sha256.ComputeHash(byteData);

            return(BitConverter.ToString(result).Replace("-", "").ToLower());
        }
コード例 #42
0
        //public string GenerateSHA256Hash(string secretkey, string timestamp, string apiKey)
        //{
        //	try
        //	{
        //		var secretKeyByteArray = Convert.FromBase64String(secretkey);
        //		//var secretKeyByteArray = Encoding.UTF8.GetBytes(secretkey);
        //		string input = $"{apiKey}{timestamp}";
        //		byte[] signature = Encoding.UTF8.GetBytes(input);

        //		using (HMACSHA256 hmac = new HMACSHA256(secretKeyByteArray))
        //		{
        //			byte[] signatureBytes = hmac.ComputeHash(signature);

        //			return Convert.ToBase64String(signatureBytes);
        //		}
        //	}
        //	catch (Exception ex)
        //	{
        //		logger.Error(ex);
        //		return "";
        //	}
        //}

        public string GenerateSHA256Hash(string secretkey, string timestamp, string apikey, string recieptref)
        {
            string input = $"{secretkey}{timestamp}{apikey}{recieptref}";
            var    shama = new System.Security.Cryptography.SHA256Managed();

            byte[] crypto = shama.ComputeHash(Encoding.UTF8.GetBytes(input));
            return(Convert.ToBase64String(crypto));
        }
コード例 #43
0
 public string GenerateSHA256Hash(String input, String salt)
 {
     byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input + salt);
     System.Security.Cryptography.SHA256Managed sHAHashString =
         new System.Security.Cryptography.SHA256Managed();
     byte[] hash = sHAHashString.ComputeHash(bytes);
     return(ByteArrayToHexString(hash));
 }
コード例 #44
0
 /// <summary>
 /// sha256加密返回base64编码
 /// </summary>
 /// <param name="strIN"></param>
 /// <returns></returns>
 public static byte[] SHA256EncryptOutByte(string strIN)
 {
     System.Security.Cryptography.SHA256 s256 = new System.Security.Cryptography.SHA256Managed();
     byte[] byte1;
     byte1 = s256.ComputeHash(Encoding.Default.GetBytes(strIN));
     s256.Clear();
     return(byte1);
 }
コード例 #45
0
 /// <summary>
 /// SHA256加密,不可逆转
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public static string ToSHA256(this string obj)
 {
     System.Security.Cryptography.SHA256 s256 = new System.Security.Cryptography.SHA256Managed();
     byte[] byte1;
     byte1 = s256.ComputeHash(Encoding.Default.GetBytes(obj));
     s256.Clear();
     return(BitConverter.ToString(byte1).Replace("-", ""));
 }
コード例 #46
0
    private String GenerateSHA256Hash(String input, String salt)
    {
        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input + salt);
        System.Security.Cryptography.SHA256Managed hashString = new System.Security.Cryptography.SHA256Managed();
        byte[] hash = hashString.ComputeHash(bytes);

        return(Convert.ToBase64String(hash));
    }
コード例 #47
0
 public static string SHA256Hash(string textinput, string salted)
 {
     byte[] bytes = System.Text.Encoding.UTF8.GetBytes(textinput + salted);
     System.Security.Cryptography.SHA256Managed sha256str =
         new System.Security.Cryptography.SHA256Managed();
     byte[] hash = sha256str.ComputeHash(bytes);
     return(ByteArrayToHexString(hash));
 }
コード例 #48
0
ファイル: logon.aspx.cs プロジェクト: PawLipinski/Komunikator
    static byte[] GenerateSaltedHash(String passwordString, byte[] salt)
    {
        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(passwordString + salt);
        System.Security.Cryptography.SHA256Managed bytesToHash = new System.Security.Cryptography.SHA256Managed();
        byte[] hash = bytesToHash.ComputeHash(bytes);

        return(hash);
    }
コード例 #49
0
ファイル: AuthClass.cs プロジェクト: Altairseven/ApiTest
 //concatena un string y un salt y los hashea juntos.
 public static string HashIt(string toHash, string salt)
 {
     byte[] bytes = System.Text.Encoding.UTF8.GetBytes(toHash + salt);
     System.Security.Cryptography.SHA256Managed sha256String =
         new System.Security.Cryptography.SHA256Managed();
     byte[] newhash = sha256String.ComputeHash(bytes);
     return(Convert.ToBase64String(newhash));
 }
コード例 #50
0
 public static string SHA256Encrypt(string str)
 {
     System.Security.Cryptography.SHA256 s256 = new System.Security.Cryptography.SHA256Managed();
     byte[] byte1;
     byte1 = s256.ComputeHash(Encoding.Default.GetBytes(str));
     s256.Clear();
     return(BitConverter.ToString(byte1).Replace("-", "").ToLower()); //64
 }
コード例 #51
0
 public static String GenerateSHA256(String input, String salt)
 {
     byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input + salt);
     System.Security.Cryptography.SHA256Managed sha256hashstring =
         new System.Security.Cryptography.SHA256Managed();
     byte[] hash = sha256hashstring.ComputeHash(bytes);
     return(BitConverter.ToString(hash));
 }
コード例 #52
0
        private static Byte[] obtenerEncriptacion(String value)
        {
            // ToDo: Mejorar esta seccion para una mejor encriptacion.

            using (var sha = new System.Security.Cryptography.SHA256Managed( )) {
                return(sha.ComputeHash(Encoding.UTF8.GetBytes(value)));
            }
        }
コード例 #53
0
        public string HashPassword(string givenPassword, string salt)
        {
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(givenPassword + salt);
            System.Security.Cryptography.SHA256Managed sha256hashString = new System.Security.Cryptography.SHA256Managed();

            byte[] hash = sha256hashString.ComputeHash(bytes);

            return(ByteArrayToHexString(hash));
        }
コード例 #54
0
 public static string HashSHA256(string password)
 {
     using (System.Security.Cryptography.SHA256Managed crypt = new System.Security.Cryptography.SHA256Managed())
     {
         System.Text.StringBuilder hash = new System.Text.StringBuilder();
         byte[] bytes = crypt.ComputeHash(Encoding.UTF8.GetBytes(password), 0, Encoding.UTF8.GetByteCount(password));
         return(ExtensionsString.BytesToHex(bytes));
     }
 }
コード例 #55
0
        private static string encryptPassword(string password, string salt)
        {
            byte[] bytes            = Encoding.UTF8.GetBytes(password + salt);
            var    sha256HashString = new System.Security.Cryptography.SHA256Managed();

            byte[] hash = sha256HashString.ComputeHash(bytes);

            return(Convert.ToBase64String(hash) + " " + salt);
        }
コード例 #56
0
ファイル: FormKlienti.cs プロジェクト: ndriqimh/DS_1819_Gr12
        public String GjeneroSHA256Hashin(String hyrja, String salt)
        {
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(hyrja + salt);
            System.Security.Cryptography.SHA256Managed sha256hashstring =
                new System.Security.Cryptography.SHA256Managed();
            byte[] hash = sha256hashstring.ComputeHash(bytes);

            return(Convert.ToBase64String(hash));
        }
コード例 #57
0
 public static string GetStringSha256Hash(string text)
 {
     using (var sha = new System.Security.Cryptography.SHA256Managed())
     {
         byte[] textData = System.Text.Encoding.UTF8.GetBytes(text);
         byte[] hash     = sha.ComputeHash(textData);
         return(BitConverter.ToString(hash).Replace("-", string.Empty));
     }
 }
コード例 #58
0
ファイル: UserData.cs プロジェクト: dsdatta/timesheet
        public static string GenerateSHA256Hash(string input)
        {
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input);
            System.Security.Cryptography.SHA256Managed sha256hashstring = new System.Security.Cryptography.SHA256Managed();
            byte[] hash   = sha256hashstring.ComputeHash(bytes);
            string base64 = Convert.ToBase64String(hash);

            return(base64);
        }
コード例 #59
0
ファイル: Util.cs プロジェクト: mkramer74/certify
 public string GetFileSHA256(Stream stream)
 {
     using (var bufferedStream = new BufferedStream(stream, 1024 * 32))
     {
         var    sha      = new System.Security.Cryptography.SHA256Managed();
         byte[] checksum = sha.ComputeHash(bufferedStream);
         return(BitConverter.ToString(checksum).Replace("-", String.Empty).ToLower());
     }
 }
コード例 #60
0
        public static byte[] Encrypt(byte[] Data, byte[] Password)
        {
            System.Security.Cryptography.HashAlgorithm hashType = new System.Security.Cryptography.SHA256Managed();
            byte[] Hash   = hashType.ComputeHash(Password);
            var    Result = new byte[Data.Length];
            int    p      = 0;

            for (int i = 0; i < Data.Length - 1; i++)
            {
                Result[i] = (byte)(Data[i] ^ Hash[p]);
                p        += 1;
                if (p == Hash.Length)
                {
                    p    = 0;
                    Hash = hashType.ComputeHash(Hash);
                }
            }
            return(Result);
        }