Example #1
0
        //class
        public static void DecodeByteCounts(byte[] bytes, uint offset, out uint saltBytesCount, out uint initiaVectorBytesCount)
        {
            if (BytesHelper.IsNullOrEmptyArray(bytes) == true ||
                bytes.Length - offset < 2 * sizeof(uint))
            {
                throw new ArgumentException(
                          string.Format("bytes array should have {0} bytes at least.",
                                        2 * sizeof(uint)));
            }

            saltBytesCount         = BytesHelper.GetUInt32(bytes, offset);
            initiaVectorBytesCount = BytesHelper.GetUInt32(bytes, offset + sizeof(uint));
        }
Example #2
0
        public static SecureHead Decode(byte[] bytes, uint offset, uint saltBytesCount, uint initiaVectorBytesCount)
        {
            uint totalBytesCount = GetPart2BytesCount() + saltBytesCount + initiaVectorBytesCount;

            if (BytesHelper.IsNullOrEmptyArray(bytes) == true ||
                bytes.Length - offset < totalBytesCount)
            {
                throw new ArgumentException(
                          string.Format("bytes array should have {0} bytes at least.",
                                        totalBytesCount));
            }

            //part 2 (4 uints):
            uint beginIndex     = offset;
            uint length         = sizeof(uint);
            uint saltIterations = BytesHelper.GetUInt32(bytes, beginIndex);

            beginIndex += length;
            length      = sizeof(uint);
            uint saltedInitiaVectorBytesCount = BytesHelper.GetUInt32(bytes, beginIndex);

            beginIndex += length;
            length      = sizeof(uint);
            uint saltedPasswordBytesCount = BytesHelper.GetUInt32(bytes, beginIndex);

            beginIndex += length;
            length      = sizeof(uint);
            uint secureDataBytes = BytesHelper.GetUInt32(bytes, beginIndex);

            //part 3 (2 byte arraries):
            beginIndex += length;
            length      = saltBytesCount;
            string salt = BytesHelper.GetUTF8String(bytes, beginIndex, length);

            beginIndex += length;
            length      = initiaVectorBytesCount;
            string initiaVector = BytesHelper.GetUTF8String(bytes, beginIndex, length);

            return(new SecureHead(
                       salt,
                       initiaVector,
                       saltIterations,
                       saltedInitiaVectorBytesCount,
                       saltedPasswordBytesCount,
                       secureDataBytes));
        }