示例#1
0
        public Identicon(string userName, IdenticonUtils.EncryptionTypeEnum encryptionType, int size, int rounds, string salt, int quality)
        {
            this.userName = userName;
            this.size     = size;
            this.quality  = quality;

            InitalizeHash(encryptionType, rounds, salt);
        }
示例#2
0
        private void InitalizeHash(IdenticonUtils.EncryptionTypeEnum encryptionType, int rounds, string salt)
        {
            //https://crypto.stackexchange.com/questions/12795/why-do-i-need-to-add-the-original-salt-to-each-hash-iteration-of-a-password
            //Salting is best if done once not during every iteration.

            finalizedHash = !(string.IsNullOrEmpty(salt)) ? userName + salt : userName;

            if (rounds > 0)
            {
                for (int i = 0; i < rounds; i++)
                {
                    finalizedHash = GenerateHash(finalizedHash, encryptionType);
                }
            }
            else
            {
                finalizedHash = GenerateHash(finalizedHash, encryptionType);
            }

            shaMatrix = GetBooleanMatrix(finalizedHash, size);
        }
示例#3
0
        private string GenerateHash(string inputString, IdenticonUtils.EncryptionTypeEnum encryptionType)
        {
            switch (encryptionType)
            {
            case IdenticonUtils.EncryptionTypeEnum.MD5:
                return(GetMD5Hash(inputString));

            case IdenticonUtils.EncryptionTypeEnum.SHA_1:
                return(GetSHA1Hash(inputString));

            case IdenticonUtils.EncryptionTypeEnum.SHA_256:
                return(GetSHA256Hash(inputString));

            case IdenticonUtils.EncryptionTypeEnum.SHA_384:
                return(GetSHA384Hash(inputString));

            case IdenticonUtils.EncryptionTypeEnum.SHA_512:
                return(GetSHA512Hash(inputString));

            default:
                throw new ArgumentException($"ERROR: Unspecified Hash Algorithm '{encryptionType}'", nameof(encryptionType));
            }
        }
示例#4
0
 private void SHA512_Checked(object sender, RoutedEventArgs e)
 {
     encryptionType = IdenticonUtils.EncryptionTypeEnum.SHA_512;
     UpdateIdenticon();
 }
示例#5
0
 private void MD5_Checked(object sender, RoutedEventArgs e)
 {
     encryptionType = IdenticonUtils.EncryptionTypeEnum.MD5;
     UpdateIdenticon();
 }