FileSigCheck 2.0.0
See the version list below for details.
dotnet add package FileSigCheck --version 2.0.0
NuGet\Install-Package FileSigCheck -Version 2.0.0
<PackageReference Include="FileSigCheck" Version="2.0.0" />
<PackageVersion Include="FileSigCheck" Version="2.0.0" />
<PackageReference Include="FileSigCheck" />
paket add FileSigCheck --version 2.0.0
#r "nuget: FileSigCheck, 2.0.0"
#:package FileSigCheck@2.0.0
#addin nuget:?package=FileSigCheck&version=2.0.0
#tool nuget:?package=FileSigCheck&version=2.0.0
File Signature Checker
This .NET Standard 2.0 library contains code for checking file signatures in their byte marks.
The file signatures were taken fromt his helpful resource: https://filesignatures.net/ (Thanks to them!)
Supported Extensions
It currently contains file signatures for the following extensions:
- .png
- .jpg
- .jpeg
- .gif
- .doc
- .docx
- .ppt
- .pptx
- .xls
- .xlsx
- .mp3
- .wav
- .ogg
- .mpg
- .m4a
- .xml
I will add more signatures if they are requested, or if I desire them.
Base 64 Images
There is a method for checking base 64 strings to see whether they are images.
Use as FileSigCheck.IsValidBase64Image(base64string).
Currently, It will strip the metadata from the start of the string, ignoring the "image/*" MIME declarations.
Usage
A typical scenario in which I have implented this is with a file upload in .NET Core API:
static readonly string[] fileExtensions = { ".pdf", ".jpg", ".jpeg", ".png" };
public async Task<IActionResult> UploadImage([FromForm]IFormFile file)
{
var ext = Path.GetExtension(file.FileName);
/* Check the file extension in permissible file types */
if(!fileExtensions.Contains(ext))
{
return StatusCode(StatusCodes.Status415UnsupportedMediaType);
}
/* Get the file data */
using (var rs = file.OpenReadStream())
{
/* perform check */
if (!FileSecurity.IsValidFileSignature(file.FileName, rs, fileExtensions))
{
ModelState.AddModelError("File", $"Is not recognised as a {Path.GetExtension(file.FileName)} file.");
return BadRequest(ModelState);
}
/* Then do what you would normally do with that file... */
}
return Ok();
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.