Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored StegoEntry, added blazor example #10

Merged
merged 5 commits into from
Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .dockerignore

This file was deleted.

27 changes: 14 additions & 13 deletions .github/workflows/ci-build-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
name: Build and Test

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
branches: [ "master" ]
branches: ["master"]

jobs:
build-and-test:
@@ -13,14 +14,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
8 changes: 4 additions & 4 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
---
name: Lint Code

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
branches: [ "master" ]
branches: ["master"]
jobs:
run-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0

- name: Lint Code Base
uses: github/super-linter@v4
env:
VALIDATE_ALL_CODEBASE: true
FILTER_REGEX_EXCLUDE: .*tests/.*|.*\.csproj|.*\.sln
FILTER_REGEX_EXCLUDE: .*tests/.*|.*\.csproj|.*\.sln|.*examples/.*
DEFAULT_BRANCH: "master"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

16 changes: 0 additions & 16 deletions Dockerfile

This file was deleted.

12 changes: 12 additions & 0 deletions examples/StegoBlazorApp/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
70 changes: 70 additions & 0 deletions examples/StegoBlazorApp/Pages/Decode.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
@page "/decode"
@using System.IO
@using Microsoft.AspNetCore.Components.Forms

<div class="container">
<div class="row">
<InputFile OnChange="HandleSelected" accept=".jpg,.jpeg,.png,.bmp" />
</div>
<div class="row">
<div class="col-md">
@if (imageBase64 != null)
{
<div>
<img src="@imageBase64" />
</div>
<div class="d-flex justify-content-center mt-2">
<button class="btn btn-primary" @onclick="Decrypt">Decrypt</button>
</div>

}
</div>
<div class="col-md">
<div class="h-100 d-flex flex-column align-items-center justify-content-center">
@if (secret != null)
{
<div>
<p>Your secret</p>
</div>
<input class="form-control" type="text" value="@secret" readonly>
}
</div>
</div>
</div>

</div>

@code {
private string? imageBase64;
private byte[]? imageBytes;

private string? secret;

private async Task HandleSelected(InputFileChangeEventArgs e)
{
var imageFile = e.File;
if (imageFile != null)
{
using MemoryStream ms = new();
using var stream = imageFile.OpenReadStream();
await stream.CopyToAsync(ms);
imageBytes = ms.ToArray();
imageBase64 = $"data:image/png;base64,{Convert.ToBase64String(imageBytes)}";
}
}

private void Decrypt()
{
if (imageBytes == null)
{
return;
}

using var stream = new MemoryStream(imageBytes);
using var stego = new StegoCore.Stego(stream);
var result = stego.Decode(StegoCore.Algorithms.AlgorithmEnum.Lsb);

// convert result to string
secret = System.Text.Encoding.UTF8.GetString(result);
}
}
93 changes: 93 additions & 0 deletions examples/StegoBlazorApp/Pages/Embed.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
@page "/embed"
@using System.IO
@using Microsoft.AspNetCore.Components.Forms
@inject IJSRuntime JS

<div class="container">
<div class="row">
<InputFile OnChange="HandleSelected" accept=".jpg,.jpeg,.png,.bmp" />
</div>
<div class="row">
<div class="col-md">
@if (imageBase64 != null)
{
<div>
<img src="@imageBase64" />
</div>
<div class="d-flex justify-content-center mt-2">
<input type="text" @bind="secret" id="secret" placeholder="Enter your secret" class="m-2" />
<button class="btn btn-primary m-2" @onclick="Encrypt">Encrypt</button>
</div>

}
</div>
<div class="col-md">
@if (imageEncrypted != null)
{
<img src="@imageEncrypted" />
<div class="d-flex justify-content-center mt-2">
<button class="btn btn-primary" @onclick="Download">Download</button>
</div>
}
</div>
</div>

</div>

@code {
private string? imageBase64;
private byte[]? imageBytes;
private string? secret;
private byte[]? imageEncryptedBytes;
private string? imageEncrypted;


private async Task HandleSelected(InputFileChangeEventArgs e)
{
var imageFile = e.File;
if (imageFile != null)
{
using MemoryStream ms = new();
var format = "image/png";
using var stream = imageFile.OpenReadStream();
await stream.CopyToAsync(ms);
imageBytes = ms.ToArray();
imageBase64 = $"data:{format};base64,{Convert.ToBase64String(imageBytes)}";
}
}

private async Task Encrypt()
{
if (secret is null || imageBytes is null)
{
return;
}

var secretData = System.Text.Encoding.UTF8.GetBytes(secret);
using (var stream = new MemoryStream(imageBytes))
{
using (var stego = new StegoCore.Stego(stream))
{
var imageWithSecret = stego.Embed(new StegoCore.Core.SecretData(secretData), StegoCore.Algorithms.AlgorithmEnum.Lsb);
using var outputStream = new MemoryStream();
await imageWithSecret.SaveAsync(outputStream, new SixLabors.ImageSharp.Formats.Png.PngEncoder());
imageEncryptedBytes = outputStream.ToArray();
imageEncrypted = $"data:image/png;base64,{Convert.ToBase64String(imageEncryptedBytes)}";
}
}
}

private async Task Download()
{
if (imageEncryptedBytes is null)
{
return;
}

var stream = new MemoryStream(imageEncryptedBytes);

using var streamRef = new DotNetStreamReference(stream: stream);

await JS.InvokeVoidAsync("downloadFileFromStream", "encrypted.png", streamRef);
}
}
42 changes: 42 additions & 0 deletions examples/StegoBlazorApp/Pages/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@page
@model StegoBlazorApp.Pages.ErrorModel

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Error</title>
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true" />
</head>

<body>
<div class="main">
<div class="content px-4">
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
</div>
</div>
</body>

</html>
26 changes: 26 additions & 0 deletions examples/StegoBlazorApp/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace StegoBlazorApp.Pages;

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
7 changes: 7 additions & 0 deletions examples/StegoBlazorApp/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@page "/"

<PageTitle>Index</PageTitle>

<h1>Hello from StegoCore!</h1>

This example show how to use StegoCore library
Loading