コード例 #1
0
ファイル: DigitalSignatures.cs プロジェクト: tej0402/Kryptor
        private static bool IsPreHashingRequired(string filePath)
        {
            int  oneGibibyte = 1024 * Constants.Mebibyte;
            long fileSize    = FileHandling.GetFileLength(filePath);

            return(fileSize >= oneGibibyte);
        }
コード例 #2
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));
        }
コード例 #3
0
ファイル: EncryptFile.cs プロジェクト: smalltsky/Kryptor
        private static byte[] EncryptFileHeader(string inputFilePath, byte[] dataEncryptionKey, byte[] nonce, byte[] keyEncryptionKey)
        {
            byte[] keyCommitmentBlock = ChunkHandling.GetKeyCommitmentBlock();
            long   fileLength         = FileHandling.GetFileLength(inputFilePath);

            byte[] lastChunkLength = BitConverter.GetBytes(Convert.ToInt32(fileLength % Constants.FileChunkSize));
            byte[] fileNameLength  = FileHeaders.GetFileNameLength(inputFilePath);
            byte[] fileHeader      = Utilities.ConcatArrays(keyCommitmentBlock, lastChunkLength, fileNameLength, dataEncryptionKey);
            byte[] additionalData  = HeaderEncryption.ComputeAdditionalData(fileLength);
            return(HeaderEncryption.Encrypt(fileHeader, nonce, keyEncryptionKey, additionalData));
        }
コード例 #4
0
ファイル: HeaderEncryption.cs プロジェクト: smalltsky/Kryptor
        public static byte[] GetAdditionalData(string inputFilePath)
        {
            byte[] magicBytes    = FileHeaders.ReadMagicBytes(inputFilePath);
            byte[] formatVersion = FileHeaders.ReadFileFormatVersion(inputFilePath);
            FileHeaders.ValidateFormatVersion(inputFilePath, formatVersion, Constants.EncryptionVersion);
            long fileLength    = FileHandling.GetFileLength(inputFilePath);
            int  headersLength = FileHeaders.GetHeadersLength();

            byte[] ciphertextLength = BitConverter.GetBytes(fileLength - headersLength);
            return(Utilities.ConcatArrays(magicBytes, formatVersion, ciphertextLength));
        }
コード例 #5
0
        private static byte[] GetFileBytes(string filePath, bool preHashed)
        {
            int  oneGibibyte = 1024 * Constants.Mebibyte;
            long fileSize    = FileHandling.GetFileLength(filePath);

            if (fileSize >= oneGibibyte || preHashed)
            {
                using var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, Constants.FileStreamBufferSize, FileOptions.SequentialScan);
                return(Blake2.Hash(fileStream));
            }
            return(File.ReadAllBytes(filePath));
        }
コード例 #6
0
 private static IEnumerable <string> GetFileEncryptionErrors(char[] password, string keyfilePath, string[] filePaths)
 {
     if (password.Length == 0 && string.IsNullOrEmpty(keyfilePath))
     {
         yield return("Please specify whether to use a password and/or keyfile.");
     }
     if (File.Exists(keyfilePath))
     {
         long keyfileLength = FileHandling.GetFileLength(keyfilePath);
         if (keyfileLength < Constants.KeyfileLength)
         {
             yield return("Please specify a keyfile that is at least 64 bytes in size.");
         }
     }
     if (filePaths == null)
     {
         yield return(ValidationMessages.FilePath);
     }
 }
コード例 #7
0
 private static IEnumerable <string> GetFileEncryptionErrors(char[] password, string keyfilePath, string[] filePaths)
 {
     if (password.Length == 0 && string.IsNullOrEmpty(keyfilePath))
     {
         yield return(ValidationMessages.PasswordOrKeyfile);
     }
     if (File.Exists(keyfilePath))
     {
         long keyfileLength = FileHandling.GetFileLength(keyfilePath);
         if (keyfileLength < Constants.KeyfileLength)
         {
             yield return("Please specify a keyfile that is at least 64 bytes in size.");
         }
     }
     else if (Path.EndsInDirectorySeparator(keyfilePath) && !Directory.Exists(keyfilePath))
     {
         yield return("Please specify a valid keyfile directory.");
     }
     if (filePaths == null)
     {
         yield return(ValidationMessages.FilePath);
     }
 }