Components
Keydecryption

Key Decryption

The "Key Decryption" component lets a user decrypt their secret key.

Features

  • Collects secret key, and salt phrase.
  • Provides a straightforward form for users to decrypt their secret key.
ℹ️

Currently using CDNJS Stanford Javascript Crypto Library v1.0.8 for instant decryption in the browser

Additional Resources

SJCL (Stanford JavaScript Crypto Library) is a secure cryptographic library that employs industry-standard security measures. It utilizes the AES (Advanced Encryption Standard) algorithm at varying key lengths of 128, 192, or 256 bits, along with the SHA256 hash function, HMAC (Hash-based Message Authentication Code) for authentication, PBKDF2 (Password-Based Key Derivation Function 2) for password strengthening, and authenticated-encryption modes like CCM and OCB.

Moreover, SJCL comes with sensible default parameters. It enhances password security by a factor of 1000 and incorporates salting to protect against rainbow table attacks. Additionally, SJCL authenticates every message it sends to safeguard against unauthorized modifications.

C#

Install the Pakana.Stellar.Components NuGet package via the NuGet Package Manager Console.

.Net8.0 or greater is required.

dotnet add package Pakana.Stellar.Components
ℹ️

StellarSDK Dependency will install automatically

NuGet Package Implementation
<pakana.stellar.components.Pages.DecryptKey/>
C#
@page "/Dkey"
@rendermode InteractiveAuto
 
@inject IJSRuntime JSRuntime
 
 
 
<h1>Secret Key Decryption</h1>
<form id="decryptionForm">
    <label for="encryptedKey">Encrypted Key:</label>
    <textarea id="encryptedKey" rows="5" cols="50"
              required></textarea><br><br>
    <label for="decryptionSalt">Decryption Salt:</label>
    <input type="text" id="decryptionSalt" required><br><br>
    <button type="submit">Decrypt Key</button>
</form>
<div id="decryptedKey"></div>
<button id="copyDecryptedKeyButton" style="display: none;">
    Copy Decrypted Key
</button>
 
@code {
    private string encryptedKey;
    private string decryptionSalt;
    private string decryptedKey;
    private bool showCopyDecryptedKeyButton = false;
 
    private async Task HandleDecryption()
    {
        decryptedKey = await JSRuntime.InvokeAsync<string>("decryptionFunction", encryptedKey, decryptionSalt);
        showCopyDecryptedKeyButton = true;
        StateHasChanged();
    }
 
    private async Task CopyDecryptedKeyToClipboard()
    {
        await JSRuntime.InvokeVoidAsync("copyDecryptedKeyToClipboard", decryptedKey);
    }
}
 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/sjcl/1.0.8/sjcl.js"></script>
<script src="your-file-path/decryptKey.js"></script>

Javascript

We've provided simple HTML and JavaScript that can be used in your project as partial-components or be customized and integrated into your existing codebase.

Stellar CDN
*Current Version as of 2024-24-02*
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/11.2.2/stellar-sdk.js"></script>
Stanford CDN
<script src="https://cdnjs.cloudflare.com/ajax/libs/sjcl/1.0.8/sjcl.js"></script>
JavaScript
 
<script>
    document.getElementById('decryptionForm').addEventListener('submit', function (event) {
        event.preventDefault();
 
    const encryptedSecretKeyTextarea = document.getElementById('encryptedSecretKey');
    const saltInput = document.getElementById('salt');
 
    if (!encryptedSecretKeyTextarea || !saltInput) {
        displayError('Required elements not found.');
    return;
            }
 
    const encryptedSecretKey = encryptedSecretKeyTextarea.value.trim();
    const salt = saltInput.value.trim();
 
    // Generate key for decryption using the provided salt
    const key = sjcl.misc.pbkdf2(salt, salt, 1000, 256);
 
    try {
                // Decrypt the encrypted secret key with the generated key
                const decryptedSecretKey = sjcl.decrypt(key, encryptedSecretKey);
 
    // Display the decrypted secret key
    const decryptedSecretKeyHtml = `
    <p><strong>Decrypted Secret Key:</strong> ${decryptedSecretKey}</p>
    `;
    document.getElementById('decryptedSecretKey').innerHTML = decryptedSecretKeyHtml;
 
    // Show the copy button
    document.getElementById('copyButton').style.display = 'inline';
            } catch (error) {
        displayError(`Decryption Error: ${error.message}`);
            }
        });
 
    // Function to copy the decrypted secret key to clipboard
    document.getElementById('copyButton').addEventListener('click', function () {
            const decryptedSecretKeyText = document.getElementById('decryptedSecretKey').textContent;
    const textarea = document.createElement('textarea');
    textarea.value = decryptedSecretKeyText;
    document.body.appendChild(textarea);
    textarea.select();
    document.execCommand('copy');
    document.body.removeChild(textarea);
    alert('Decrypted Secret Key copied to clipboard!');
        });
 
    function displayError(message) {
            const errorHtml = `<p><strong>Error:</strong> ${message}</p>`;
    document.getElementById('decryptedSecretKey').innerHTML = errorHtml;
        }
</script>
 
 
HTML
 
<body>
    <h1>Secret Key Decryption</h1>
 
    <form id="decryptionForm">
        <label for="encryptedSecretKey">Encrypted Secret Key:</label>
        <textarea id="encryptedSecretKey" rows="5" cols="50" required></textarea><br><br>
 
        <label for="salt">Encryption Salt:</label>
        <input type="text" id="salt" required><br><br>
 
        <button type="submit">Decrypt Secret Key</button>
    </form>
 
    <div id="decryptedSecretKey"></div>
 
    <button id="copyButton" style="display: none;">Copy Decrypted Secret Key</button>
 
</body>