Exemple #1
0
        public int Length(byte bType)
        {
            String2KeySpecifierTypes s2kstType = (String2KeySpecifierTypes)bType;

            switch (s2kstType)
            {
            case String2KeySpecifierTypes.SimpleS2K:
                return(2);

            case String2KeySpecifierTypes.SaltedS2K:
                return(10);

            case String2KeySpecifierTypes.IteraterSaltedS2K:
                return(11);
            }

            return(0);
        }
        public void ParseSpecifier(byte[] bSpecifier)
        {
            if (bSpecifier.Length < 2) {
                throw(new System.ArgumentException("Not a valid String2Key specifier!"));
            }
            this.Type = (String2KeySpecifierTypes)bSpecifier[0];
            this.HashAlgorithm = (HashAlgorithms)bSpecifier[1];

            if (this.Type == String2KeySpecifierTypes.SaltedS2K ||
                this.Type == String2KeySpecifierTypes.IteraterSaltedS2K) {
                if (bSpecifier.Length < 10) {
                    throw(new System.ArgumentException("Not a valid String2Key specifier!"));
                }
                lSalt = ((ulong)bSpecifier[2]) << 56;
                lSalt ^= ((ulong)bSpecifier[3]) << 48;
                lSalt ^= ((ulong)bSpecifier[4]) << 40;
                lSalt ^= ((ulong)bSpecifier[5]) << 32;
                lSalt ^= ((ulong)bSpecifier[6]) << 24;
                lSalt ^= ((ulong)bSpecifier[7]) << 16;
                lSalt ^= ((ulong)bSpecifier[8]) << 8;
                lSalt ^= ((ulong)bSpecifier[9]);
            }

            if (this.Type == String2KeySpecifierTypes.IteraterSaltedS2K) {
                if (bSpecifier.Length < 11) {
                    throw(new System.ArgumentException("Not a valid String2Key specifier!"));
                }
                bCount = bSpecifier[10];
            }
        }