Пример #1
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));
 }
Пример #2
0
        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));
        }
Пример #3
0
        public static bool VerifySignature(string signatureFilePath, string filePath, byte[] publicKey, out string comment)
        {
            using var signatureFile = new FileStream(signatureFilePath, FileMode.Open, FileAccess.Read, FileShare.Read, Constants.FileStreamBufferSize, FileOptions.SequentialScan);
            byte[] magicBytes    = GetMagicBytes(signatureFile);
            byte[] formatVersion = GetFormatVersion(signatureFile);
            FileHeaders.ValidateFormatVersion(formatVersion, Constants.SignatureVersion);
            byte[] preHashed            = GetPreHashedHeader(signatureFile);
            byte[] fileSignature        = GetFileSignature(signatureFile);
            byte[] commentBytes         = GetCommentBytes(signatureFile);
            byte[] signatureFileBytes   = Arrays.Concat(magicBytes, formatVersion, preHashed, fileSignature, commentBytes);
            bool   validGlobalSignature = VerifyGlobalSignature(signatureFile, signatureFileBytes, publicKey);

            if (!validGlobalSignature)
            {
                comment = string.Empty;
                return(false);
            }
            bool preHash = BitConverter.ToBoolean(preHashed);

            byte[] fileBytes = GetFileBytes(filePath, preHash);
            comment = Encoding.UTF8.GetString(commentBytes);
            return(PublicKeyAuth.VerifyDetached(fileSignature, fileBytes, publicKey));
        }
Пример #4
0
        public static bool VerifySignature(string signatureFilePath, string filePath, byte[] publicKey)
        {
            using var signatureFile = new FileStream(signatureFilePath, FileMode.Open, FileAccess.Read, FileShare.Read, Constants.FileStreamBufferSize, FileOptions.RandomAccess);
            // Verify the global signature
            byte[] magicBytes    = GetMagicBytes(signatureFile);
            byte[] formatVersion = GetFormatVersion(signatureFile);
            FileHeaders.ValidateFormatVersion(signatureFilePath, formatVersion, Constants.SignatureVersion);
            byte[] preHashedHeader = GetPreHashedHeader(signatureFile);
            byte[] fileSignature   = GetFileSignature(signatureFile);
            _commentBytes = GetCommentBytes(signatureFile);
            byte[] signatureFileBytes   = Utilities.ConcatArrays(magicBytes, formatVersion, preHashedHeader, fileSignature, _commentBytes);
            bool   validGlobalSignature = VerifyGlobalSignature(signatureFile, signatureFileBytes, publicKey);

            if (!validGlobalSignature)
            {
                return(false);
            }
            // Verify the file signature
            bool preHashed = BitConverter.ToBoolean(preHashedHeader);

            byte[] fileBytes = GetFileBytes(filePath, preHashed);
            return(PublicKeyAuth.VerifyDetached(fileSignature, fileBytes, publicKey));
        }