{"id":26558130,"url":"https://github.com/simpson-computer-technologies-research/rsa-azure-key-vault-encryption","last_synced_at":"2025-03-22T12:30:53.620Z","repository":{"id":278299216,"uuid":"935164932","full_name":"Simpson-Computer-Technologies-Research/rsa-azure-key-vault-encryption","owner":"Simpson-Computer-Technologies-Research","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-19T02:26:29.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-02-19T03:25:43.386Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Simpson-Computer-Technologies-Research.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-02-19T02:23:42.000Z","updated_at":"2025-02-19T02:26:32.000Z","dependencies_parsed_at":"2025-02-19T03:35:57.597Z","dependency_job_id":null,"html_url":"https://github.com/Simpson-Computer-Technologies-Research/rsa-azure-key-vault-encryption","commit_stats":null,"previous_names":["simpson-computer-technologies-research/rsa-azure-key-vault-encryption"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Simpson-Computer-Technologies-Research%2Frsa-azure-key-vault-encryption","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Simpson-Computer-Technologies-Research%2Frsa-azure-key-vault-encryption/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Simpson-Computer-Technologies-Research%2Frsa-azure-key-vault-encryption/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Simpson-Computer-Technologies-Research%2Frsa-azure-key-vault-encryption/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Simpson-Computer-Technologies-Research","download_url":"https://codeload.github.com/Simpson-Computer-Technologies-Research/rsa-azure-key-vault-encryption/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244959412,"owners_count":20538625,"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":[],"created_at":"2025-03-22T12:30:52.731Z","updated_at":"2025-03-22T12:30:53.513Z","avatar_url":"https://github.com/Simpson-Computer-Technologies-Research.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# RSA Azure Key-Vault Encryption\n\nEnterprise-level encryption\n\n```ts\n//\n//\n// FRONTEND\n//\n//\n\nimport forge from \"node-forge\";\nimport axios from \"axios\";\n\n/**\n * Get public key from Azure Key Vault\n * \n * @param azureAccessToken Azure access token\n * \n * @returns Public key\n * \n * @example\n * const publicKey = await getPublicKey({ azureAccessToken });\n */\nexport const getPublicKey = async ({ azureAccessToken }: { azureAccessToken: string }) =\u003e {\n    const url = \"https://\u003cYOUR_KEYVAULT_NAME\u003e.vault.azure.net/keys/MyRSAKey?api-version=7.3\";\n\n    const res = await axios.get(url, {\n        headers: {\n            Authorization: `Bearer ${azureAccessToken}`,\n        }\n    });\n\n    const json = await res.json();\n\n    return json.key.n;\n}\n\n/**\n * Encrypt data with a public key (RSA)\n * \n * @param data Data to encrypt\n * @param publicKey Public key to encrypt with\n * @param expiresAt Expiration date in milliseconds\n * \n * @returns Encrypted data\n * \n * @example\n * const publicKey = await getPublicKey({ azureAccessToken });\n * const encrypted = await encrypt({ data: \"Hello, World!\", publicKey, expiresAt: Date.now() + 3600 * 1000 }); // Expires in 1 hour\n */\nexport const encrypt = async ({ data, publicKey, expiresAt }: Readonly\u003c{ data: string | undefined; publicKey: string; expiresAt?: number }\u003e) =\u003e {\n    const _toEncrypt = expiresAt !== undefined ? JSON.stringify({ data, expiresAt }) : data;\n\n    const _publicKey = forge.pki.publicKeyFromPem(publicKey);\n\n    const encrypted = _publicKey.encrypt(_toEncrypt, \"RSA-OAEP\");\n\n    return forge.util.encode64(encrypted);\n}\n\n//\n//\n// BACKEND\n//\n//\n\n/**\n * Decrypt data with a private key (RSA)\n * \n * @param data Data to decrypt\n * @param privateKey Private key to decrypt with\n * \n * @returns Decrypted data\n * \n * @example\n * const decrypted = await decrypt({ data: encrypted, azureAccessToken });\n */\nexport const decrypt = async ({ data, azureAccessToken }: Readonly\u003c{ data: string | undefined; azureAccessToken: string; }\u003e) =\u003e {\n    const url = \"https://\u003cYOUR_KEYVAULT_NAME\u003e.vault.azure.net/decrypt?api-version=7.3\";\n\n    const res = await axios.post(url, {\n        alg: \"RSA-OAEP\",\n        value: data,\n    }, {\n        headers: {\n            Authorization: `Bearer ${azureAccessToken}`,\n            \"Content-Type\": \"application/json\",\n        }\n    });\n\n    const json = await res.json();\n\n    return forge.util.decode64(json.value);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimpson-computer-technologies-research%2Frsa-azure-key-vault-encryption","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimpson-computer-technologies-research%2Frsa-azure-key-vault-encryption","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimpson-computer-technologies-research%2Frsa-azure-key-vault-encryption/lists"}