Beispiel #1
0
        public static byte[] ComputeAdditionalData(long fileLength, byte[] ephemeralPublicKey)
        {
            long chunkCount = (long)Math.Ceiling((double)fileLength / Constants.FileChunkSize);

            byte[] ciphertextLength = BitConversion.GetBytes(chunkCount * Constants.TotalChunkLength);
            return(Arrays.Concat(ciphertextLength, Constants.KryptorMagicBytes, Constants.EncryptionVersion, ephemeralPublicKey));
        }
Beispiel #2
0
 public static byte[] GetAdditionalData(FileStream inputFile, byte[] ephemeralPublicKey)
 {
     byte[] ciphertextLength = BitConversion.GetBytes(inputFile.Length - Constants.FileHeadersLength);
     byte[] magicBytes       = FileHeaders.ReadMagicBytes(inputFile);
     byte[] formatVersion    = FileHeaders.ReadFileFormatVersion(inputFile);
     FileHeaders.ValidateFormatVersion(formatVersion, Constants.EncryptionVersion);
     return(Arrays.Concat(ciphertextLength, magicBytes, formatVersion, ephemeralPublicKey));
 }
Beispiel #3
0
        private static byte[] EncryptFileHeader(string inputFilePath, byte[] ephemeralPublicKey, byte[] dataEncryptionKey, byte[] nonce, byte[] keyEncryptionKey)
        {
            long fileLength = FileHandling.GetFileLength(inputFilePath);

            byte[] lastChunkLength = BitConversion.GetBytes(Convert.ToInt32(fileLength % Constants.FileChunkSize));
            byte[] fileNameLength  = FileHeaders.GetFileNameLength(inputFilePath);
            byte[] fileHeader      = Arrays.Concat(lastChunkLength, fileNameLength, dataEncryptionKey);
            byte[] additionalData  = HeaderEncryption.ComputeAdditionalData(fileLength, ephemeralPublicKey);
            return(HeaderEncryption.Encrypt(fileHeader, nonce, keyEncryptionKey, additionalData));
        }
Beispiel #4
0
        public static byte[] GetFileNameLength(string inputFilePath)
        {
            if (!Globals.ObfuscateFileNames)
            {
                return(BitConversion.GetBytes(0));
            }
            string fileName = Path.GetFileName(inputFilePath);

            byte[] fileNameBytes = Encoding.UTF8.GetBytes(fileName);
            return(BitConversion.GetBytes(fileNameBytes.Length));
        }