feat: implement hybrid encryption and compress public key URLs (Fixes… - #15
Open
Adityakk9031 wants to merge 1 commit into
Open
feat: implement hybrid encryption and compress public key URLs (Fixes…#15Adityakk9031 wants to merge 1 commit into
Adityakk9031 wants to merge 1 commit into
Conversation
Author
|
@asadeddin have a look |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes:#13
Summary
This PR implements hybrid encryption (RSA-OAEP + AES-GCM-256) and public key modulus minification to resolve two primary user issues:
n(reducing the URL length to under 380 characters).Both changes are fully backward-compatible with older URLs.
Changes Made
Cryptography Layer (
js/crypto.js)encryptString/decryptString):[RSA-Encrypted AES Key (256 bytes) | IV (12 bytes) | AES Ciphertext (variable)]and encodes it to Base64.decryptStringchecks the byte length of the decoded payload. If it is exactly 256 bytes, it automatically decrypts using the legacy RSA-only logic.serialize_key/deserialize_key):serialize_keydetects RSA public keys and extracts only their modulusnparameter, yielding a compact 342-character string. Private keys still serialize as full JWK JSON.deserialize_keydetects old JWKs by checking for theey(Base64 JSON{) prefix. If not present, it dynamically reconstructs the JWK using the string as the modulusnandAQABas the exponent.bufferToBase64andbase64ToBufferto safely encode/decode binary data without call stack limit exceptions on large secrets.load_private_keyfunction.How to Test
You can run the automated test suite in Node.js, or manually verify directly in the browser:
1. Run Tests (Node.js)
Execute the testing script: