Key Encryption
The "Key Encryption" component lets a user encrypt their secret key.
Features
- Collects secret key, and salt phrase.
- Provides a straightforward form for users to encrypt 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
<pakana.stellar.components.Pages.EncryptKey/>
@page "/Key"
@rendermode InteractiveAuto
@inject IJSRuntime JSRuntime
<h1>Secret Key Encryption</h1>
<form id="encryptionForm">
<label for="secretKeyon">Secret Key:</label>
<input type="text" id="secretKeyon" required><br><br>
<label for="salton">Encryption Salt:</label>
<input type="text" id="salton" required><br><br>
<button type="submit">Encrypt Secret Key</button>
</form>
<div id="encryptedSecretKey"></div>
<button id="copyButton" style="display: none;">Copy Encrypted Secret
Key</button>
@code {
private string secretData;
private string encryptedSecretKey;
private string salton;
private string result;
private bool showCopyButton = false;
private async Task HandleEncryption()
{
result = await JSRuntime.InvokeAsync<string>("encryptKey", secretData, salton);
encryptedSecretKey = result; // Store encrypted result for possible decryption
showCopyButton = true;
StateHasChanged();
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/sjcl/1.0.8/sjcl.js"></script>
<script src="your-file-path/encryptKey.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.
*Current Version as of 2024-24-02*
<script src="https://cdnjs.cloudflare.com/ajax/libs/stellar-sdk/11.2.2/stellar-sdk.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sjcl/1.0.8/sjcl.js"></script>
<script>
document.getElementById('encryptionForm').addEventListener('submit', function (event) {
event.preventDefault();
const secretKey = document.getElementById('secretKey').value.trim();
const salt = document.getElementById('salt').value.trim();
// Generate key for encryption using salt
const key = sjcl.misc.pbkdf2(salt, salt, 1000, 256);
// Encrypt the secret key with the generated key
const encryptedSecretKey = sjcl.encrypt(key, secretKey);
// Display the encrypted secret key
const encryptedSecretKeyHtml = `
<p><strong>Encrypted Secret Key:</strong> ${encryptedSecretKey}</p>
`;
document.getElementById('encryptedSecretKey').innerHTML = encryptedSecretKeyHtml;
// Show the copy button
document.getElementById('copyButton').style.display = 'inline';
});
// Function to copy the encrypted secret key to clipboard
document.getElementById('copyButton').addEventListener('click', function () {
const encryptedSecretKeyText = document.getElementById('encryptedSecretKey').textContent;
const textarea = document.createElement('textarea');
textarea.value = encryptedSecretKeyText;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
alert('Encrypted Secret Key copied to clipboard!');
});
</script>
<body>
<h1>Secret Key Encryption</h1>
<form id="encryptionForm">
<label for="secretKey">Secret Key:</label>
<input type="text" id="secretKey" required><br><br>
<label for="salt">Encryption Salt:</label>
<input type="text" id="salt" required><br><br>
<button type="submit">Encrypt Secret Key</button>
</form>
<div id="encryptedSecretKey"></div>
<button id="copyButton" style="display: none;">Copy Encrypted Secret Key</button>
</body>