{"id":17511719,"url":"https://github.com/telkomdev/crypsi","last_synced_at":"2025-04-23T12:55:45.539Z","repository":{"id":49339345,"uuid":"517377028","full_name":"telkomdev/crypsi","owner":"telkomdev","description":"Custom crypto utility that wraps the crypto node module to make life easier (Digest, Cipher, HMAC, RSA, RSA Digital Signature)","archived":false,"fork":false,"pushed_at":"2024-10-17T03:00:32.000Z","size":113,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-19T05:15:11.819Z","etag":null,"topics":["crypto","digest","hash","nodejs","rsa","telkomdev"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/crypsi","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/telkomdev.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":"2022-07-24T16:28:04.000Z","updated_at":"2024-10-16T18:57:55.000Z","dependencies_parsed_at":"2024-12-10T04:43:29.365Z","dependency_job_id":null,"html_url":"https://github.com/telkomdev/crypsi","commit_stats":{"total_commits":103,"total_committers":2,"mean_commits":51.5,"dds":0.4563106796116505,"last_synced_commit":"bab2569718845836a08957f5a5f40453cb31b293"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fcrypsi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fcrypsi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fcrypsi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/telkomdev%2Fcrypsi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/telkomdev","download_url":"https://codeload.github.com/telkomdev/crypsi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250439294,"owners_count":21430822,"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":["crypto","digest","hash","nodejs","rsa","telkomdev"],"created_at":"2024-10-20T05:09:00.367Z","updated_at":"2025-04-23T12:55:45.515Z","avatar_url":"https://github.com/telkomdev.png","language":"JavaScript","readme":"## crypsi (Node Crypto Utility)\n\nCustom crypto utility that wraps the `crypto` node module to make life easier\n\n[![crypsi Node CI](https://github.com/telkomdev/crypsi/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/telkomdev/crypsi/actions/workflows/ci.yml)\n\n### Install\n```shell\n$ npm i crypsi\n```\n\n### Crypsi is compatible with each other with the following libraries\n- Golang https://github.com/telkomdev/go-crypsi\n- Python https://github.com/telkomdev/pycrypsi\n- C# (.NET) https://github.com/telkomdev/NetCrypsi\n- Java/JVM https://github.com/telkomdev/jcrypsi\n- Javascript (React and Browser) https://github.com/telkomdev/crypsi.js\n\n### Usage\n\nJust open the `unit test` folder, all available there.\n\n### Features\n- Asymmetric encryption with RSA\n- Generate RSA private and public key\n- Digital Signature with RSA private and public key using PSS\n- Symmetric encryption with AES\n- Message authentication code with HMAC\n- Generate Hash with Common DIGEST Algorithm\n\n#### Example Generate RSA Private and Public Key\n\n##### Javascript\n```javascript\nconst { rsa, keyUtil } = require('crypsi');\nconst fs = require('fs');\n\nrsa.generateRSAKeyPair(keyUtil.KEY_SIZE_4KB, '').then(pairs =\u003e {\n    console.log(pairs.publicKey);\n    console.log(pairs.privateKey);\n\n    console.log('\\n');\n    console.log(rsa.loadPrivateKeyAsBase64(pairs.privateKey));\n    console.log('\\n');\n    console.log(rsa.loadPublicKeyAsBase64(pairs.publicKey));\n\n    const publicKeyWriter = fs.createWriteStream('public.key');\n    publicKeyWriter.write(pairs.publicKey);\n    \n    const privateKeyWriter = fs.createWriteStream('private.key');\n    privateKeyWriter.write(pairs.privateKey);\n\n    publicKeyWriter.close();\n    privateKeyWriter.close();\n}).catch(err =\u003e {\n    console.log(err);\n});\n```\n\n##### Typescript\n```javascript\nimport { digest, rsa, rsaSign, keyUtil } from 'crypsi';\nimport fs from 'fs';\n\nasync function generate() {\n    const pairs = await rsa.generateRSAKeyPair(keyUtil.KEY_SIZE_2KB);\n\n    const publicKeyWriter = fs.createWriteStream('public.key');\n    publicKeyWriter.write(pairs.publicKey);\n    \n    const privateKeyWriter = fs.createWriteStream('private.key');\n    privateKeyWriter.write(pairs.privateKey);\n\n    publicKeyWriter.close();\n    privateKeyWriter.close();\n}\n\ngenerate();\n```\nResult RSA Public Key\n```\n-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwIrVMXSXC5vxh+0fJny0\n5neOzrb3kqvGOzLBgza4Emxj+MRLqzn1MtcSFobjwqlWoof8/5ycV0L74fhOywcX\nn61vHwik/8As0HkyWK8yRd98T1Q5Z8U+ZYrl959h96Bi6il6y4IN+t7A8lfV2Rvz\nUMEl9agfg0xNqPhEUFHCyDYzM7dW9cmSHyUhl+rp9RA/udNkv/k4ak7C4YmQEZyg\nb9uEVlFY5Bpod5rZGm6roWqwZ54neDREuI4E7fWTnDXbYqif6/lNcBDvKW9s5oqx\nYecNjMsrNrXQHkndoFENouzirQSITbxmwMAE5sJsU0RcFFP0yjsMtfSPSN48ubFH\nmQIDAQAB\n-----END PUBLIC KEY-----\n```\n\nResult RSA Private Key\n\n```\n-----BEGI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Jivc5ZMmZMD8CTgtJLRcJDOe1YjwqnEqU3kcuX5lvbXczZOVIU0PW6kmd\nLTJtRJZy6QKBgCu8/pJuwQjIZ6tOjidwn7fFxg9GXQO3lyqkCAgN+YP9zPh0R3co\nIIWwGlpvAjVj+57fkxyblJzD8fe+0uHh4zK3h+8bVkgk7taUIBe/J7xB4cadDXT7\nWMBjQYsrCdzXOeKZjIxiUZfmLIGQY5eO5h+MJsI3t1pqdDJTGdYaN+ihAoGAcrj+\n0aQ3xhO2qzMnRtCcSyUU7Iz0qocFWDy2OaVTwq63d+jvX44wrcmwy08ayfEqaSeR\nK7km/c0PxoM/S2keZjNcc3vxDfDojCcdT5U9zSFxoLSgIEDtEOei1xwEiS8MDycy\n9Av/W/gSbKmTSWOP314AUtmeR/RonpxrvIpb1kECgYAiRqS7MDwPVsktnzuT9ZWx\nHDfktrdWAHO5+S2zG9gbCOgnhiOyIq4GakHgbdVlj2xsisOMGULFXEJBP3v8SzgF\n7V2kM7+ThdnmQJaQC561871hb9gh5hOkf/GO9Gxe0cBOF4HmHO+QiQvylLdx/w8X\nn3LQsISpln3R7g8riWFeWg==\n-----END PRIVATE KEY-----\n```\n\n#### Example Loading RSA Private and Public Key\n```javascript\nconst { rsa } = require('crypsi');\nconst fs = require('fs');\n\n// loading RSA private key from file\nconst privateKeyData = fs.readFileSync('./testdata/private.key');\nconst privateKey = rsa.loadPrivateKey(privateKeyData);\n\nconsole.log(privateKey);\n\n// loading RSA public key from file\nconst publicKeyData = fs.readFileSync('./testdata/public.key');\nconst publicKey = rsa.loadPublicKey(publicKeyData);\n\nconsole.log(publicKey);\n```\n\n#### Example Loading RSA Private and Public Key as Base64 String\n```javascript\nconst { rsa } = require('crypsi');\nconst fs = require('fs');\n\n// loading RSA private key from file\nconst privateKeyData = fs.readFileSync('./testdata/private.key');\nconst privateKeyBase64 = rsa.loadPrivateKeyAsBase64(privateKeyData);\n\nconsole.log(privateKeyBase64);\n\n// loading RSA public key from file\nconst publicKeyData = fs.readFileSync('./testdata/public.key');\nconst publicKeyBase64 = rsa.loadPublicKeyAsBase64(publicKeyData);\n\nconsole.log(publicKeyBase64);\n```\n\n#### Example Loading RSA Private and Public Key as Base64 String and load back as RSA private and public key\n```javascript\nconst { rsa } = require('crypsi');\nconst fs = require('fs');\n\n// loading RSA private key from file\nconst privateKeyData = fs.readFileSync('./testdata/private.key');\nconst privateKeyBase64 = rsa.loadPrivateKeyAsBase64(privateKeyData);\n\n// for example: save privateKeyBase64 to database\nconst privateKey = rsa.loadPrivateKeyFromBase64(privateKeyBase64);\nconsole.log(privateKey);\n\n// loading RSA public key from file\nconst publicKeyData = fs.readFileSync('./testdata/public.key');\nconst publicKeyBase64 = rsa.loadPublicKeyAsBase64(publicKeyData);\n\n// for example: save publicKeyBase64 to database\n\nconst publicKey = rsa.loadPublicKeyFromBase64(publicKeyBase64);\nconsole.log(publicKey);\n```\n\n#### Example Digital Signature with RSA Private and Public Key\n\n```javascript\nconst { rsa, rsaSign, keyUtil } = require('crypsi');\nconst { Buffer } = require('buffer');\nconst fs = require('fs');\n\nrsa.generateRSAKeyPair(keyUtil.KEY_SIZE_4KB, '').then(pairs =\u003e {\n    console.log(pairs.publicKey);\n    console.log(pairs.privateKey);\n\n    // data can be anything, from simple string or Buffer of file\n    const fileData = fs.readFileSync('./testdata/myfile.txt');\n\n    // sign with private key\n    const signature = rsaSign.signWithPSSSha256(pairs.privateKey, Buffer.from(fileData));\n\n     // =\u003e for example: save signature to database\n\n    // verifying digital signature with public key\n    const signatureValid = rsaSign.verifyWithPSSSha256(pairs.publicKey, signature, Buffer.from(fileData));\n    console.log(signatureValid);\n}).catch(err =\u003e {\n    console.log(err);\n});\n```\n\n#### Example Encryption with RSA Private and Public Key\n```javascript\nconst { rsa, rsaEncryption, keyUtil } = require('crypsi');\nconst fs = require('fs');\n\nrsa.generateRSAKeyPair(keyUtil.KEY_SIZE_4KB, '').then(pairs =\u003e {\n    console.log(pairs.publicKey);\n    console.log(pairs.privateKey);\n\n    // data can be anything, from simple string or Buffer of file\n    const fileData = fs.readFileSync('./testdata/myfile.txt');\n\n    // encrypt with public key\n    const encryptedData = rsaEncryption.encryptWithOaepSha256(pairs.publicKey, fileData);\n\n    // decrypt with private key\n    const decryptedData = rsaEncryption.decryptWithOaepSha256(pairs.privateKey, encryptedData);\n\n    console.log(decryptedData);\n}).catch(err =\u003e {\n    console.log(err);\n});\n```\n\n#### Example Generate Hash with common Digest Algorithm\n```javascript\nconst { digest } = require('crypsi');\n\nconst data = 'hello world';\n\n// MD5\nconst generatedHashMd5 = digest.md5(data);\nconsole.log(generatedHashMd5);\n\n// SHA1\nconst generatedHashSha1 = digest.sha1(data);\nconsole.log(generatedHashSha1);\n\n// SHA256\nconst generatedHashSha256 = digest.sha256(data);\nconsole.log(generatedHashSha256);\n\n// SHA384\nconst generatedHashSha384 = digest.sha384(data);\nconsole.log(generatedHashSha384);\n\n// SHA512\nconst generatedHashSha512 = digest.sha512(data);\nconsole.log(generatedHashSha512);\n```\n\n#### Example Generate Hash with HMAC\nKeyed-Hash Message Authentication Code (HMAC) as defined in U.S. Federal Information Processing Standards Publication 198. An HMAC is a cryptographic hash that uses a key to sign a message (from Golang Documentation).\n```javascript\nconst { hmac } = require('crypsi');\n\nconst key = 'abc$#128djdyAgbjau\u0026YAnmcbagryt5x';\nconst data = 'hello world';\n\n// MD5\nconst generatedHmacMd5 = hmac.md5(key, data);\nconsole.log(generatedHmacMd5);\n\n// SHA1\nconst generatedHmacSha1 = hmac.sha1(key, data);\nconsole.log(generatedHmacSha1);\n\n// SHA256\nconst generatedHmacSha256 = hmac.sha256(key, data);\nconsole.log(generatedHmacSha256);\n\n// SHA384\nconst generatedHmacSha384 = hmac.sha384(key, data);\nconsole.log(generatedHmacSha384);\n\n// SHA512\nconst generatedHmacSha512 = hmac.sha512(key, data);\nconsole.log(generatedHmacSha512);\n```\n\n#### Example Encryption with AES Algorithm\nExpected key len:\n- AES 128: key length should be 16 bytes\n- AES 192: key length should be 24 bytes\n- AES 256: key length should be 32 bytes\n\nData encryption with `AES 256 CBC`\n```javascript\nconst { aesEncryption } = require('crypsi');\n\nconst key = 'abc$#128djdyAgbjau\u0026YAnmcbagryt5x';\nconst data = 'hello world';\n\n// encrypt data with AES 256 CBC\nconst encryptedData = aesEncryption.encryptWithAes256Cbc(key, data);\nconsole.log(encryptedData);\n\n// decrypt data with AES 256 CBC with the same key\nconst decryptedData = aesEncryption.decryptWithAes256Cbc(key, encryptedData);\nconsole.log(decryptedData);\n```\n\nFile encryption with `AES 256 CBC`\n\n```javascript\nconst fs = require('fs');\nconst { aesEncryption } = require('crypsi');\n\nconst key128 = 'abc$#128djdyAgbj';\n\nfs.readFile('myfile.jpg', null, (err, data) =\u003e {\n    if (err) {\n        console.log(err);\n    } else {\n        \n        const encrypted = aesEncryption.encryptWithAes128Cbc(key128, data);\n        // store encrypted data and its nonce for example to the database or to the file system\n        console.log(encrypted.encrypted);\n\n        const decryptedData = aesEncryption.decryptWithAes128Cbc(key128, encrypted);\n        \n        // write decrypted data back to the file\n        fs.writeFile('out.jpg', decryptedData, 'binary', (err) =\u003e {\n            if (err) {\n                console.log('error... ', err);\n            }\n        });\n    }\n});\n```\n\nFile Decryption with `AES 256 OCB`\n```javascript\nconst fs = require('fs');\nconst { aesEncryption } = require('crypsi');\n\nconst key256 = 'abc$#128djdyAgbjau\u0026YAnmcbagryt5x';\n\nfs.readFile('./test/testdata/out.bin', null, (err, data) =\u003e {\n    if (err) {\n      throw err;\n    }\n\n    const decryptedData = aesEncryption.decryptWithAes256Ocb(key256, Buffer.from(data.toString(), 'hex'));\n\n    fs.writeFileSync('out.png', decryptedData);\n  });\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftelkomdev%2Fcrypsi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftelkomdev%2Fcrypsi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftelkomdev%2Fcrypsi/lists"}