{"id":15655202,"url":"https://github.com/torxed/slimcrypt","last_synced_at":"2025-03-24T01:44:28.136Z","repository":{"id":150500827,"uuid":"220446241","full_name":"Torxed/slimCrypt","owner":"Torxed","description":"Javascript wrapper for JS crypto.subtle.encrypt() using one-time-key's transmitted via private/public keypairs.","archived":false,"fork":false,"pushed_at":"2019-11-09T14:51:19.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-25T16:58:49.295Z","etag":null,"topics":["javascript","one-time-pad","private-key","public-key-cryptography","subtlecrypto","wrapper"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Torxed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-08T10:44:56.000Z","updated_at":"2019-11-09T14:41:48.000Z","dependencies_parsed_at":"2023-07-29T01:15:21.331Z","dependency_job_id":null,"html_url":"https://github.com/Torxed/slimCrypt","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Torxed%2FslimCrypt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Torxed%2FslimCrypt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Torxed%2FslimCrypt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Torxed%2FslimCrypt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Torxed","download_url":"https://codeload.github.com/Torxed/slimCrypt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245195908,"owners_count":20575936,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","one-time-pad","private-key","public-key-cryptography","subtlecrypto","wrapper"],"created_at":"2024-10-03T12:57:00.367Z","updated_at":"2025-03-24T01:44:28.116Z","avatar_url":"https://github.com/Torxed.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# slimCrypt\nJavascript wrapper for [window.crypto.subtle.encrypt()](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt) using one-time-key's transmitted via private/public keypairs.\n\n# Installation\n\n```html\n\u003cscript type=\"text/javascript\"\u003e\n\t// Loading JavaScript from a cross-site resource is blocked.\n\t// But there's nothing stopping us from downloading the script\n\t// as a text-blob and placing it within the \u003cscript\u003e \u003c/ script\u003e tags,\n\t// which causes the browser to parse it, but not as a forrain object.\n\t//\n\t// #LoadingScriptsFromGithub\n\tvar script = document.createElement('script');\n\tscript.type = 'text/javascript';\n\n\tlet xhr = new XMLHttpRequest();\n\txhr.open(\"GET\", 'https://raw.githubusercontent.com/Torxed/slimCrypt/master/slimCrypt.js', true);\n\txhr.onreadystatechange = function() {\n\t\tif (this.readyState === XMLHttpRequest.DONE \u0026\u0026 this.status === 200) {\n\t\t\tscript.innerHTML = this.responseText;\n\t\t\tdocument.head.appendChild(script);\n\t\t}\n\t}\n\txhr.send();\n\u003c/script\u003e\n```\n\n# Usage\n\n### Encrypting a string\n\n```javascript\nlet string_to_be_encrypted = \"A message or something\";\ngenerate_one_time_key((one_time_key) =\u003e {\n    encrypt_with_key(string_to_be_encrypted, one_time_key, (encrypt_struct) =\u003e {\n        wrap_key_in_pubkey(encrypt_struct, one_time_key, connected_to['publicKey'], (wrapped_key) =\u003e {\n            let struct = {\n                'payload': encrypt_struct['b64_encrypted_payload'],\n                'key' : wrapped_key,\n                'iv' : btoa(encrypt_struct['iv']),\n                'key_format' : encrypt_struct['key_format'],\n                \"access_token\": access_token\n            }\n            socket.send(struct);\n        });\n    });\n})\n```\n\n### Decrypting a string\n\n```javascript\nlet struct = {\n    'payload': encrypt_struct['b64_encrypted_payload'],\n    'key' : wrapped_key,\n    'iv' : btoa(encrypt_struct['iv']),\n    'key_format' : encrypt_struct['key_format'],\n    \"access_token\": access_token\n}\n\nlet array = JSON.parse(\"[\"+atob(struct['payload'])+\"]\");\nlet encrypted_message = new Uint8Array(array);\nlet one_time_key_wrapped = new Uint8Array(JSON.parse(\"[\"+atob(struct['key'])+\"]\"));\n\nload_private_key(keys['privateKey'], (privateKey) =\u003e {\n    extract_one_time_key(one_time_key_wrapped, privateKey, (one_time_key) =\u003e {\n        let options = {\n            name: struct['key_format'],\n            iv: new Uint8Array(JSON.parse(\"[\"+atob(struct['iv'])+\"]\"))\n        };\n        decrypt_with_key(options, one_time_key, encrypted_message, (decrypted_message) =\u003e {\n            console.log(decrypted_message)\n        });\n    });\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftorxed%2Fslimcrypt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftorxed%2Fslimcrypt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftorxed%2Fslimcrypt/lists"}