Example #1
0
        /// <summary>
        /// The Equals method determines whether the specified System.Object is equal to the current System.Object.
        /// </summary>
        public override bool Equals(object obj)
        {
            if (obj.GetType() != typeof(SplitArray))
            {
                return(false);
            }

            SplitArray value = (SplitArray)obj;

            return(Utility.CompareArrays(this.FirstArray(), value.FirstArray()) &&
                   Utility.CompareArrays(this.SecondArray(), value.SecondArray()));
        }
Example #2
0
        /// <summary>
        /// Initialize the <see cref="DerivedKeys"/> instance with the passphrase, the
        /// IV and the salt.
        /// </summary>
        /// <param name="passphrase">User passprhase</param>
        /// <param name="algorithm">See <see cref="SymmetricAlgorithm"/>.</param>
        /// <param name="packedData">The packed data (salt+data) bytes.</param>
        public DerivedKeys(string passphrase, SymmetricAlgorithm algorithm, ref byte[] packedData)
        {
            //Extract salt from packedKeys
            SplitArray unpacked = Utility.SplitArrays(packedData, algorithm.KeySize >> 3);

            _salt = unpacked.FirstArray();

            // Pin the keys in memory to prevents the garbage collector from moving the
            // object and hence undermines the efficiency of the garbage collector
            // threfore, we should call dispose after using these keys.
            PinKeys(passphrase, algorithm.BlockSize >> 3);

            // Return clean data blob
            packedData = unpacked.SecondArray();
        }
Example #3
0
 /// <summary>
 /// Compares two byte arrays.
 /// </summary>
 /// <param name="value">The <see cref="SplitArray"/> containing the two arrays to compare.</param>
 /// <returns>True if the arrays are equals; false otherwise.</returns>
 public static bool CompareArrays(SplitArray value)
 {
     return(CompareArrays(value.FirstArray(), value.SecondArray()));
 }
Example #4
0
 /// <summary>
 /// Joins two arrays into one.
 /// </summary>
 /// <param name="value">The <see cref="SplitArray"/> containing the two arrays to join</param>
 /// <returns>The union of the two arrays.</returns>
 /// <exception cref="ArgumentNullException">The specified parameter is a null reference (Nothing in Visual Basic).</exception>
 /// <exception cref="ArgumentOutOfRangeException">The lenght of the two arrays is gretar thant the <see cref="int.MaxValue"/>.</exception>
 public static byte[] JoinArrays(SplitArray value)
 {
     return(JoinArrays(value.FirstArray(), value.SecondArray()));
 }