Skip to content

Commit

Permalink
Fixed #5.
Browse files Browse the repository at this point in the history
  • Loading branch information
GlitchedPolygons committed Dec 16, 2023
1 parent a020282 commit f25584a
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 168 deletions.
24 changes: 11 additions & 13 deletions GlitchedPolygons.GlitchEd25519.BlazorWebApp/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,14 @@

<div style="display: flex; flex-wrap: wrap; gap: 12px; margin-top: 1.5rem">
<button class="btn btn-primary stretch-when-narrow"
disabled="@(encryptionPlaintext.NullOrEmpty() || privateKeyHexStringRef10.NullOrEmpty() || publicKeyHexString.NullOrEmpty())"
style="padding-left: 24px; padding-right: 24px;"
@onclick="EncryptString">
Encrypt
</button>

<button class="btn btn-primary stretch-when-narrow"
disabled="@(encryptionCiphertext.NullOrEmpty() || encryptionCiphertext.Contains("error", StringComparison.InvariantCultureIgnoreCase))"
style="padding-left: 24px; padding-right: 24px; min-width: 162px;"
id="copyCiphertextButton"
@onclick="CopyEncryptionCiphertextToClipboard">
Expand Down Expand Up @@ -254,6 +256,7 @@

<div style="display: flex; flex-wrap: wrap; gap: 12px; margin-top: 1.5rem">
<button class="btn btn-primary stretch-when-narrow"
disabled="@(decryptionCiphertext.NullOrEmpty() || privateKeyHexStringRef10.NullOrEmpty() || publicKeyHexString.NullOrEmpty())"
style="padding-left: 24px; padding-right: 24px;"
@onclick="DecryptString">
Decrypt
Expand All @@ -273,19 +276,6 @@

</div>

<script type="text/javascript">
const copyCiphertextButton = document.getElementById('copyCiphertextButton');
const defaultLabelCopyCiphertextButton = copyCiphertextButton.innerHTML;
copyCiphertextButton.addEventListener('click', () =>
{
copyCiphertextButton.innerHTML = 'Copied...';
setTimeout(() => copyCiphertextButton.innerHTML = defaultLabelCopyCiphertextButton, 1337);
});
</script>

@code
{
private readonly bool aesGcmSupported = AesGcm.IsSupported;
Expand All @@ -300,6 +290,14 @@
private string publicKeyHexString = string.Empty;
private string privateKeyHexStringRef10 = string.Empty;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JSRuntime.InvokeVoidAsync("InitCopyButtonLabel", "copyCiphertextButton");
}
}

private void EncryptString()
{
if (encryptionPlaintext.NullOrEmpty())
Expand Down
166 changes: 14 additions & 152 deletions GlitchedPolygons.GlitchEd25519.BlazorWebApp/Pages/Keygen.razor
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@

<button class="btn btn-primary stretch-when-narrow"
id="copyPublicKeyButton"
disabled="@publicKeyHexString.NullOrEmpty()"
style="padding-left: 24px; padding-right: 24px; min-width: 162px;"
@onclick="CopyPublicKey">
Copy public key
</button>

<button class="btn btn-primary stretch-when-narrow"
id="copyPrivateKeyButton"
disabled="@privateKeyHexString.NullOrEmpty()"
style="padding-left: 24px; padding-right: 24px; min-width: 162px;"
@onclick="CopyPrivateKey">
Copy private key
Expand All @@ -118,158 +120,6 @@
<br />
<br />

<script type="text/javascript">
const keygenButton = document.getElementById('keygenButton');
const entropy = document.getElementById('paintCanvasEntropy');
const paintCanvas = document.querySelector('.js-paint');
const context = paintCanvas.getContext('2d');
let x = 0, y = 0;
let isMouseDown = false;
const configContext = () =>
{
context.strokeStyle = '#401bc2';
context.lineCap = 'round';
context.lineWidth = 4;
}
configContext();
const stopDrawing = () =>
{
isMouseDown = false;
}
const startDrawing = event =>
{
event.preventDefault();
isMouseDown = true;
if (event.changedTouches)
{
const boundingRect = paintCanvas.getBoundingClientRect();
[x, y] =
[
event.changedTouches[0].clientX - boundingRect.left,
event.changedTouches[0].clientY - boundingRect.top
];
}
else
{
[x, y] =
[
event.offsetX,
event.offsetY
];
}
}
const drawLine = event =>
{
event.preventDefault();
if (isMouseDown)
{
const boundingRect = paintCanvas.getBoundingClientRect();
const newX = event.changedTouches
? event.changedTouches[0].clientX - boundingRect.left
: event.offsetX;
const newY = event.changedTouches
? event.changedTouches[0].clientY - boundingRect.top
: event.offsetY;
context.beginPath();
context.moveTo(x, y);
context.lineTo(newX, newY);
context.stroke();
x = newX;
y = newY;
entropy.value = newX + newY;
entropy.dispatchEvent(new Event('input', { bubbles: true }));
}
}
const clearCanvas = () =>
{
context.clearRect(0, 0, paintCanvas.width, paintCanvas.height);
//setTimeout(() => context.clearRect(0, 0, paintCanvas.width, paintCanvas.height), 2048);
}
paintCanvas.addEventListener('mousedown', startDrawing);
paintCanvas.addEventListener('touchstart', startDrawing);
paintCanvas.addEventListener('mousemove', drawLine);
paintCanvas.addEventListener('touchmove', drawLine);
paintCanvas.addEventListener('mouseup', stopDrawing);
paintCanvas.addEventListener('mouseout', stopDrawing);
paintCanvas.addEventListener('touchend', stopDrawing);
paintCanvas.addEventListener('touchcancel', stopDrawing);
const copyPublicKeyButton = document.getElementById('copyPublicKeyButton');
const defaultLabelCopyPublicKeyButton = copyPublicKeyButton.innerHTML;
const copyPrivateKeyButton = document.getElementById('copyPrivateKeyButton');
const defaultLabelCopyPrivateKeyButton = copyPrivateKeyButton.innerHTML;
copyPublicKeyButton.addEventListener('click', () =>
{
copyPublicKeyButton.innerHTML = 'Copied...';
setTimeout(() => copyPublicKeyButton.innerHTML = defaultLabelCopyPublicKeyButton, 1337);
});
copyPrivateKeyButton.addEventListener('click', () =>
{
copyPrivateKeyButton.innerHTML = 'Copied...';
setTimeout(() => copyPrivateKeyButton.innerHTML = defaultLabelCopyPrivateKeyButton, 1337);
});
keygenButton.addEventListener('click', clearCanvas);
const onResize = function(event)
{
const windowDimensions =
{
width: window.innerWidth,
height: window.innerHeight
};
if (windowDimensions.width < 641)
{
paintCanvas.width = windowDimensions.width - 50;
paintCanvas.height = 256;
}
else if (windowDimensions.width < 1250)
{
paintCanvas.width = windowDimensions.width - 260;
paintCanvas.height = 384;
}
else
{
paintCanvas.width = 1024;
paintCanvas.height = 512;
}
configContext();
};
window.addEventListener('resize', onResize, true);
onResize(null);
</script>

@code {

private readonly bool aesGcmSupported = AesGcm.IsSupported;
Expand All @@ -287,6 +137,18 @@

private uint? additionalEntropyCRC32 = null;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await Task.Delay(64);

await JSRuntime.InvokeVoidAsync("InitCopyButtonLabel", "copyPublicKeyButton");
await JSRuntime.InvokeVoidAsync("InitCopyButtonLabel", "copyPrivateKeyButton");
await JSRuntime.InvokeVoidAsync("InitKeygen");
}
}

private void OnAddAdditionalEntropy(ChangeEventArgs eventArgs)
{
additionalEntropy = (additionalEntropy + eventArgs.Value).SHA512();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
<meta name="keywords" content="asymmetric, cryptography, aes, gcm, ed25519, eddsa, dsa, public key, private key">
<meta name="author" content="Glitched Polygons">
<title>GlitchEd25519</title>
<link rel="manifest" href="ed25519.webmanifest" />
<base href="/"/>
<link rel="icon" type="image/png" href="favicon.png"/>
<link rel="manifest" href="ed25519.webmanifest" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css"/>
<link rel="stylesheet" href="css/app.css"/>
<link rel="icon" type="image/png" href="favicon.png"/>
<link href="GlitchedPolygons.GlitchEd25519.BlazorWebApp.styles.css" rel="stylesheet"/>
</head>

Expand Down Expand Up @@ -44,6 +44,10 @@

<script src="_framework/blazor.webassembly.js"></script>

<script src="js/keygen.js"></script>

<script src="js/copybutton.js"></script>

</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

function InitCopyButtonLabel(buttonElementId)
{
const copyButton = document.getElementById(buttonElementId);
const defaultLabelCopyButton = copyButton.innerHTML;

copyButton.addEventListener('click', () =>
{
copyButton.innerHTML = 'Copied...';

setTimeout(() => copyButton.innerHTML = defaultLabelCopyButton, 1337);
});
}
Loading

0 comments on commit f25584a

Please sign in to comment.