Esempio n. 1
0
        /// <summary>
        /// Converts variables into easy-to-manage method calls to create a byte array for metadata
        /// </summary>
        /// <param name="checksumHashType">Type of checksum used to generate the file hash</param>
        /// <param name="originalFileHash">File hash of the original file (checksum generated using previous hash type)</param>
        /// <param name="passwordHint">A password hint for the password used to encrypt the file</param>
        /// <param name="compressionModeUsed">Compression mode used to compress the file</param>
        /// <param name="originalFileName">The name of the original file</param>
        public DynamicMetadata(Checksums.ChecksumType checksumHashType, byte[] originalFileHash, string passwordHint, string compressionModeUsed, string originalFileName)
        {
            _faesIdentifier      = CryptUtils.ConvertStringToBytes(CryptUtils.GetCryptIdentifier());
            _hashType            = CryptUtils.ConvertChecksumTypeToBytes(checksumHashType);
            _originalFileHash    = originalFileHash;
            _encryptionTimestamp = BitConverter.GetBytes((long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds);
            _passwordHint        = CryptUtils.ConvertStringToBytes(passwordHint.TrimEnd('\n', '\r'));
            _encryptionVersion   = CryptUtils.ConvertStringToBytes(FileAES_Utilities.GetVersion());
            _compressionMode     = CryptUtils.ConvertStringToBytes(compressionModeUsed);
            _originalFileName    = CryptUtils.ConvertStringToBytes(originalFileName);

            _totalMetadataSize = (4 + 2 + _faesIdentifier.Length + 2 + _hashType.Length + 2 + _originalFileHash.Length + 2 + _encryptionTimestamp.Length + 2 + _passwordHint.Length + 2 + _encryptionVersion.Length + 2 + _compressionMode.Length + 2 + _originalFileName.Length);
        }
Esempio n. 2
0
        /// <summary>
        /// Converts a ChecksumType to a byte array.
        /// </summary>
        /// <param name="checksumHashType">Checksum Type</param>
        /// <returns>Byte Array</returns>
        public static byte[] ConvertChecksumTypeToBytes(Checksums.ChecksumType checksumHashType)
        {
            switch (checksumHashType)
            {
            case Checksums.ChecksumType.SHA1:
                return(BitConverter.GetBytes(1));

            case Checksums.ChecksumType.SHA256:
                return(BitConverter.GetBytes(2));

            case Checksums.ChecksumType.SHA512:
                return(BitConverter.GetBytes(3));

            case Checksums.ChecksumType.SHA384:
                return(BitConverter.GetBytes(4));

            default:
                return(BitConverter.GetBytes(0));
            }
        }
Esempio n. 3
0
 public MetaData(Checksums.ChecksumType checksumHashType, byte[] originalFileHash, string passwordHint, string compressionModeUsed, string originalFileName)
 {
     _dynamicMetadata = new DynamicMetadata(checksumHashType, originalFileHash, passwordHint, compressionModeUsed, originalFileName);
 }