From 9b0b64131511cbf0ee9da3fe28adad5644781ab4 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 09:57:34 +0000 Subject: [PATCH 1/2] Add URL encoding, Punycode and AES modes tools, and finish hashing New Toolbox pages for percent encoding, Punycode and AES in ten modes with a padding picker. The hash tool lists every hashlib variant and can set the SHAKE output length, the HMAC tool adds keyed BLAKE2, and the TOTP tool adds HOTP. Snippets that use codec helpers now import package:hashlib/codecs.dart. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01KmuCbv3a5X5mMTT8iAKym8 --- src/components/toolbox/Aes.astro | 203 ++++++++++++++++++++++++++ src/components/toolbox/Codec.astro | 3 + src/components/toolbox/Hash.astro | 17 ++- src/components/toolbox/Hmac.astro | 36 ++++- src/components/toolbox/Punycode.astro | 66 +++++++++ src/components/toolbox/Totp.astro | 33 ++++- src/lib/toolbox-copy.ts | 76 +++++++++- src/lib/toolbox.ts | 96 +++++++++--- src/pages/toolbox/[tool].astro | 12 +- 9 files changed, 509 insertions(+), 33 deletions(-) create mode 100644 src/components/toolbox/Aes.astro create mode 100644 src/components/toolbox/Punycode.astro diff --git a/src/components/toolbox/Aes.astro b/src/components/toolbox/Aes.astro new file mode 100644 index 0000000..ed77441 --- /dev/null +++ b/src/components/toolbox/Aes.astro @@ -0,0 +1,203 @@ +--- +// AES in the classic modes. GCM lives on the "Encrypt and decrypt" tool. +const modes = [ + ['cbc', 'CBC'], + ['ctr', 'CTR'], + ['ecb', 'ECB'], + ['cfb', 'CFB (128-bit)'], + ['cfb8', 'CFB8'], + ['ofb', 'OFB'], + ['ccm', 'CCM (authenticated)'], + ['xts', 'XTS (disk encryption)'], + ['pcbc', 'PCBC'], + ['ige', 'IGE'], +]; +const paddings = [ + ['pkcs7', 'PKCS#7'], + ['ansi', 'ANSI X9.23'], + ['byte', 'ISO/IEC 7816-4'], + ['zero', 'Zero bytes'], + ['none', 'None'], +]; +--- + +
+
+
+ + +
+
+ + +
+ +
+

+ +
+
+ + +
+ +

+
+
+
+ + +
+ +

+
+ + +
+ + +
+ +
+
+
+ + +
+ +
+
+ +
+ + +
+
+ + +
+
+ + diff --git a/src/components/toolbox/Codec.astro b/src/components/toolbox/Codec.astro index 1061b87..6832f50 100644 --- a/src/components/toolbox/Codec.astro +++ b/src/components/toolbox/Codec.astro @@ -34,6 +34,9 @@ const LABELS: Record = { base62: 'Base62', base36: 'Base36', base45: 'Base45', + percent: 'Percent-encoded (RFC 3986)', + 'percent-component': 'Like encodeURIComponent', + 'percent-form': 'Form data (space as +)', }; --- diff --git a/src/components/toolbox/Hash.astro b/src/components/toolbox/Hash.astro index 893f617..070eb33 100644 --- a/src/components/toolbox/Hash.astro +++ b/src/components/toolbox/Hash.astro @@ -46,7 +46,13 @@ const { ids, common } = Astro.props;
- +
+ + +
diff --git a/src/components/toolbox/Totp.astro b/src/components/toolbox/Totp.astro index 6e4e065..d3173dd 100644 --- a/src/components/toolbox/Totp.astro +++ b/src/components/toolbox/Totp.astro @@ -4,6 +4,10 @@ ---
+
+ + +
@@ -28,14 +32,19 @@
-
+ +
-
+ +

Current code

@@ -53,7 +62,7 @@
diff --git a/src/lib/toolbox-copy.ts b/src/lib/toolbox-copy.ts index b53f7f2..0972aa2 100644 --- a/src/lib/toolbox-copy.ts +++ b/src/lib/toolbox-copy.ts @@ -26,7 +26,7 @@ export const toolCopy: Record = { title: 'SHA-256, SHA-3 and MD5 hash generator', about: [ 'A hash function turns any input into a short, fixed-size digest. The same input always gives the same digest, and changing one byte changes it completely. Hashes are used to check downloads, spot changed files, and build signatures and identifiers.', - 'Type text or drop in a file of up to 256 MB, and this page shows its digest under every supported algorithm at once: SHA-256, SHA-512, SHA-3, BLAKE2, Keccak-256, RIPEMD-160, SM3, SHA-1, MD5 and more. Input can be UTF-8 text, hex or Base64, and digests are shown in lowercase hex, uppercase hex or Base64.', + 'Type text or drop in a file of up to 256 MB, and this page shows its digest under every supported algorithm at once: SHA-256, SHA-512, SHA-3, BLAKE2, Keccak-256, RIPEMD-160, SM3, SHA-1, MD5 and more. Input can be UTF-8 text, hex or Base64, and digests are shown in lowercase hex, uppercase hex or Base64. Under “Show all algorithms” you can also set the output length of SHAKE128 and SHAKE256.', ], faq: [ { @@ -63,10 +63,10 @@ export const toolCopy: Record = { ], }, hmac: { - title: 'HMAC-SHA256 generator', + title: 'HMAC-SHA256 and keyed BLAKE2 generator', about: [ 'An HMAC is a hash of a message mixed with a secret key. Anyone holding the key can recompute it to check that the message came from someone else with the key and was not changed. Webhooks, API request signing and session cookies commonly use HMAC-SHA256.', - 'Enter a key and a message as text, hex or Base64, pick the hash, and read the HMAC in hex, Base64 or Base64URL.', + 'Enter a key and a message as text, hex or Base64, pick the hash, and read the HMAC in hex, Base64 or Base64URL. BLAKE2 also has its own keyed mode, defined in RFC 7693, which is faster than HMAC and is offered here at every BLAKE2b and BLAKE2s length.', ], faq: [ { @@ -77,6 +77,10 @@ export const toolCopy: Record = { q: 'Is an HMAC the same as a hash of key + message?', a: 'No. Hashing the key and message together is open to length-extension attacks with SHA-256 and similar hashes. HMAC, defined in RFC 2104, hashes in two nested passes to avoid that.', }, + { + q: 'Is keyed BLAKE2 the same as HMAC-BLAKE2?', + a: 'No, they give different results. Keyed BLAKE2 feeds the key into the hash’s own parameter block and needs a single pass, while HMAC wraps BLAKE2 in two passes. Use whichever the other side expects.', + }, LOCAL, ], }, @@ -148,6 +152,46 @@ export const toolCopy: Record = { LOCAL, ], }, + url: { + title: 'URL encode and decode online', + about: [ + 'URLs may only contain a small set of characters. Anything else, such as a space, an ampersand or a non-English letter, is written as a percent sign followed by the byte value in hex. This is percent encoding, defined in RFC 3986, and it is what urlencode and encodeURIComponent do.', + 'Type text on the left to encode it, or paste an encoded string on the right to decode it. There are three styles: strict RFC 3986, the encodeURIComponent style that also keeps ! \' ( ) *, and form data, where a space becomes +.', + ], + faq: [ + { + q: 'Should a space be %20 or +?', + a: 'In a URL path, always %20. In a query string sent by an HTML form (application/x-www-form-urlencoded), a space is written as +. Most servers accept %20 in a query string too.', + }, + { + q: 'Why is é encoded as %C3%A9?', + a: 'Text is first turned into UTF-8 bytes, and é is two bytes in UTF-8, C3 and A9. Each byte gets its own percent escape.', + }, + { + q: 'What is the difference between encodeURI and encodeURIComponent?', + a: 'encodeURI leaves characters that have a meaning in a full URL, such as / ? & and =, untouched. encodeURIComponent escapes them, which is what you want for a single query value or path segment. This page encodes like encodeURIComponent or stricter.', + }, + LOCAL, + ], + }, + punycode: { + title: 'Punycode converter for international domain names', + about: [ + 'Domain names can only use ASCII letters, digits and hyphens, so a name like münchen.de is stored as xn--mnchen-3ya.de. The xn-- prefix marks a label written in Punycode, the encoding defined in RFC 3492 that packs Unicode into those characters.', + 'Type a Unicode domain to see its ASCII form, or paste an xn-- name to read it. Untick “Whole domain name” to convert a single label without the xn-- prefix.', + ], + faq: [ + { + q: 'Why does my browser show xn-- in the address bar?', + a: 'Browsers show the Punycode form when a name mixes scripts or looks like another domain, to protect against look-alike phishing domains.', + }, + { + q: 'Does this normalize the name the way browsers do?', + a: 'No. Browsers also lower-case and normalize the name (IDNA 2008 or UTS #46 processing) before encoding. This page encodes exactly the characters you type, so type the name in its usual lower-case form.', + }, + LOCAL, + ], + }, converter: { title: 'Base85, Z85, Base62 and Base45 converter', about: [ @@ -234,6 +278,28 @@ export const toolCopy: Record = { LOCAL, ], }, + aes: { + title: 'AES encryption and decryption: CBC, CTR, ECB, CCM, XTS', + about: [ + 'AES is a block cipher: on its own it encrypts exactly 16 bytes. A mode of operation turns it into something that can encrypt a whole message, and the mode decides how blocks are chained, whether padding is needed and what the IV does.', + 'Pick a mode, enter a key and IV in hex, and encrypt text, hex or Base64. Paste a ciphertext to decrypt it. CBC, ECB, PCBC and IGE pad the message to whole blocks, with PKCS#7 by default; CTR, CFB and OFB need no padding. CCM adds an authentication tag, as RFC 3610 defines, and XTS is the mode used for disk encryption.', + ], + faq: [ + { + q: 'Why does my AES-CBC decryption fail or give garbage?', + a: 'Usually the key, IV or padding differs from what was used to encrypt. Check that the key is the right length in bytes (not characters), that the IV is the one sent with the message, and that both sides use the same padding, most often PKCS#7. Also make sure the ciphertext is decoded from the right format, hex or Base64.', + }, + { + q: 'Which AES mode should I use?', + a: 'For new designs, an authenticated mode: AES-GCM (on the Encrypt and decrypt tool) or CCM. Use CBC, CTR and the others to work with existing systems. Avoid ECB, which leaks patterns in the data.', + }, + { + q: 'What is PKCS#7 padding?', + a: 'It fills the last block with N bytes of value N, so a message that needs 3 more bytes ends in 03 03 03. A message that is already a whole number of blocks gets a full extra block of sixteen 0x10 bytes, so the padding can always be removed without ambiguity.', + }, + LOCAL, + ], + }, 'ml-kem': { title: 'ML-KEM (Kyber) post-quantum key exchange demo', about: [ @@ -289,10 +355,10 @@ export const toolCopy: Record = { ], }, totp: { - title: 'TOTP code generator for 2FA secrets', + title: 'TOTP and HOTP code generator for 2FA secrets', about: [ 'TOTP (RFC 6238) is the algorithm behind authenticator apps. The app and the server share a secret, and every 30 seconds both compute an HMAC of the current time step and turn it into a short code.', - 'Paste a Base32 secret to see the current code and a countdown to the next one. Most services use SHA-1, 6 digits and a 30-second period, and all three can be changed.', + 'Paste a Base32 secret to see the current code and a countdown to the next one. Most services use SHA-1, 6 digits and a 30-second period, and all three can be changed. HOTP (RFC 4226), the counter-based original that hardware tokens use, is here too: enter a counter to see its code and the next four.', ], faq: [ { diff --git a/src/lib/toolbox.ts b/src/lib/toolbox.ts index cc35164..91a5c25 100644 --- a/src/lib/toolbox.ts +++ b/src/lib/toolbox.ts @@ -38,14 +38,15 @@ export const tools: Tool[] = [ id: 'hash', name: 'Hash text or file', category: 'Hash', - summary: 'SHA-2, SHA-3, BLAKE2, Keccak, RIPEMD, SM3 and MD5, all at once.', - description: 'Compute SHA-256, SHA-512, SHA-3, BLAKE2, Keccak-256, RIPEMD-160, SM3, SHA-1 and MD5 of any text or file, in your browser.', + summary: 'SHA-2, SHA-3, SHAKE, BLAKE2, Keccak, RIPEMD, SM3 and MD5, all at once.', + description: 'Compute SHA-256, SHA-512, SHA-3, SHAKE at any length, BLAKE2, Keccak-256, RIPEMD, SM3, SHA-1, MD5 and more for any text or file, in your browser.', library: 'hashlib', specs: [ FIPS('180-4', 'https://csrc.nist.gov/pubs/fips/180-4/upd1/final'), FIPS('202', 'https://csrc.nist.gov/pubs/fips/202/final'), RFC(7693), RFC(1321), + RFC(1319), ], dart: `import 'package:hashlib/hashlib.dart'; @@ -71,17 +72,21 @@ print(xxh32code('hello world'));`, }, { id: 'hmac', - name: 'HMAC', + name: 'HMAC and keyed BLAKE2', category: 'Hash', - summary: 'Sign a message with a secret key and any supported hash.', - description: 'Compute an HMAC with SHA-256, SHA-512, SHA-3, BLAKE2 and more, in your browser. The key never leaves your device.', + summary: 'Sign a message with a secret key: HMAC with any hash, or keyed BLAKE2.', + description: 'Compute an HMAC with SHA-256, SHA-512, SHA-3 and more, or a keyed BLAKE2b or BLAKE2s MAC, in your browser. The key never leaves your device.', library: 'hashlib', - specs: [RFC(2104), RFC(4231)], - dart: `import 'package:hashlib/hashlib.dart'; + specs: [RFC(2104), RFC(4231), RFC(7693)], + dart: `import 'package:hashlib/codecs.dart'; +import 'package:hashlib/hashlib.dart'; final mac = sha256.hmac.byString('secret key'); -print(mac.string('message').hex());`, - keywords: ['mac', 'signature', 'hmac-sha256', 'keyed hash'], +print(mac.string('message').hex()); + +final key = toUtf8('secret key'); +print(blake2b256.mac.by(key).string('message').hex());`, + keywords: ['mac', 'signature', 'hmac-sha256', 'keyed hash', 'blake2 mac', 'keyed blake2b'], }, // Encode { @@ -141,6 +146,35 @@ print(toBinary(bytes));`, print(toBase58(toUtf8('Hello World!'))); // 2NEpo7TZRRrLZSi2U`, keywords: ['bitcoin', 'b58', 'address'], }, + { + id: 'url', + name: 'URL encode and decode', + category: 'Encode', + summary: 'Percent-encode text for URLs and query strings, and decode it.', + description: 'Percent-encode and decode text for URLs, path segments and form data, following RFC 3986. Both directions update as you type.', + library: 'convertlib', + specs: [RFC(3986)], + dart: `import 'package:convertlib/convertlib.dart'; + +print(toPercent(toUtf8('a b&c'))); // a%20b%26c +print(toPercent(toUtf8('a b'), form: true)); // a+b +print(fromUtf8(fromPercent('caf%C3%A9'))); // café`, + keywords: ['percent encoding', 'urlencode', 'urldecode', 'query string', 'uri', 'escape'], + }, + { + id: 'punycode', + name: 'Punycode converter', + category: 'Encode', + summary: 'Turn international domain names into xn-- form and back.', + description: 'Convert internationalized domain names and labels between Unicode and Punycode (xn--), following RFC 3492.', + library: 'convertlib', + specs: [RFC(3492), RFC(3490)], + dart: `import 'package:convertlib/convertlib.dart'; + +print(toPunycode('münchen.de', domain: true)); // xn--mnchen-3ya.de +print(fromPunycode('xn--mnchen-3ya.de', domain: true));`, + keywords: ['idn', 'idna', 'xn--', 'international domain', 'unicode domain', 'emoji domain'], + }, { id: 'converter', name: 'Encoding converter', @@ -164,7 +198,8 @@ print(toBase85(bytes, codec: Base85Codec.z85)); // HelloWorld`, description: 'Hash a password with Argon2id, Argon2i or Argon2d and verify it against an encoded hash, entirely in your browser.', library: 'hashlib', specs: [RFC(9106)], - dart: `import 'package:hashlib/hashlib.dart'; + dart: `import 'package:hashlib/codecs.dart'; +import 'package:hashlib/hashlib.dart'; final hash = argon2id( toUtf8(password), @@ -182,7 +217,8 @@ final ok = argon2Verify(hash, toUtf8(password));`, description: 'Hash a password with bcrypt at the cost you choose, and verify a password against an existing bcrypt hash, in your browser.', library: 'hashlib', specs: [{ label: 'Provos and Mazières, 1999', href: 'https://www.usenix.org/legacy/events/usenix99/provos/provos.pdf' }], - dart: `import 'package:hashlib/hashlib.dart'; + dart: `import 'package:hashlib/codecs.dart'; +import 'package:hashlib/hashlib.dart'; final hash = bcrypt(toUtf8(password), bcryptSalt(nb: 10)); final ok = bcryptVerify(hash, toUtf8(password));`, @@ -220,6 +256,28 @@ final sealed = aes.encrypt(plaintext); // ciphertext + tag final opened = aes.decrypt(sealed); // throws if tampered`, keywords: ['aes', 'gcm', 'chacha20', 'poly1305', 'aead', 'cipher'], }, + { + id: 'aes', + name: 'AES modes', + category: 'Encrypt', + summary: 'AES in CBC, CTR, ECB, CFB, OFB, CCM, XTS and more, with padding options.', + description: 'Encrypt and decrypt with AES in CBC, CTR, ECB, CFB, OFB, CCM, PCBC, IGE and XTS modes, with PKCS#7 or other padding, in your browser.', + library: 'cipherlib', + specs: [ + { label: 'NIST SP 800-38A', href: 'https://csrc.nist.gov/pubs/sp/800/38/a/final' }, + RFC(3610), + { label: 'IEEE 1619', href: 'https://standards.ieee.org/ieee/1619/4205/' }, + { label: 'FIPS 197', href: 'https://csrc.nist.gov/pubs/fips/197/final' }, + ], + dart: `import 'package:cipherlib/cipherlib.dart'; + +final cbc = AES(key).cbc(iv); // PKCS#7 by default +final ciphertext = cbc.encrypt(plaintext); +final plain = cbc.decrypt(ciphertext); + +final ctr = AES(key).ctr(iv);`, + keywords: ['aes-cbc', 'aes-ctr', 'aes-ecb', 'aes-ccm', 'aes-xts', 'pkcs7', 'padding', 'iv', 'decrypt aes', 'cfb', 'ofb'], + }, { id: 'ml-kem', name: 'ML-KEM key exchange', @@ -267,17 +325,21 @@ final password = randomString(20, lower: true, upper: true, numeric: true);`, }, { id: 'totp', - name: 'TOTP codes', + name: 'TOTP and HOTP codes', category: 'Generate', - summary: 'Live two-factor codes from a shared secret.', - description: 'Show live TOTP two-factor codes for a Base32 secret, with SHA-1, SHA-256 or SHA-512 and 6 to 8 digits.', + summary: 'Two-factor codes from a shared secret: live TOTP, or HOTP by counter.', + description: 'Show live TOTP two-factor codes, or HOTP codes for a counter, from a Base32 secret, with SHA-1, SHA-256 or SHA-512 and 6 to 8 digits.', library: 'hashlib', specs: [RFC(6238), RFC(4226)], - dart: `import 'package:hashlib/hashlib.dart'; + dart: `import 'package:hashlib/codecs.dart'; +import 'package:hashlib/hashlib.dart'; final totp = TOTP(fromBase32(secret)); -print(totp.valueString());`, - keywords: ['2fa', 'otp', 'authenticator', 'one-time password', 'mfa'], +print(totp.valueString()); + +final hotp = HOTP(fromBase32(secret), counter: fromHex('0000000000000001')); +print(hotp.valueString());`, + keywords: ['2fa', 'otp', 'authenticator', 'one-time password', 'mfa', 'hotp', 'counter'], }, ]; diff --git a/src/pages/toolbox/[tool].astro b/src/pages/toolbox/[tool].astro index cec96d2..1e9280a 100644 --- a/src/pages/toolbox/[tool].astro +++ b/src/pages/toolbox/[tool].astro @@ -17,6 +17,8 @@ import MlKem from '../../components/toolbox/MlKem.astro'; import Uuid from '../../components/toolbox/Uuid.astro'; import Random from '../../components/toolbox/Random.astro'; import Totp from '../../components/toolbox/Totp.astro'; +import Punycode from '../../components/toolbox/Punycode.astro'; +import Aes from '../../components/toolbox/Aes.astro'; export function getStaticPaths() { return tools.map((tool) => ({ params: { tool: tool.id }, props: { tool } })); @@ -37,6 +39,7 @@ const codecs: Record} {tool.id === 'random' && } {tool.id === 'totp' && } + {tool.id === 'punycode' && } + {tool.id === 'aes' && }