{"id":20279339,"url":"https://github.com/simplito/xtea-js","last_synced_at":"2025-04-11T06:19:13.219Z","repository":{"id":41865808,"uuid":"44064757","full_name":"simplito/xtea-js","owner":"simplito","description":"A pure JavaScript XTEA block cipher implementation (PHP MCRYPT_XTEA compatible) with support for ECB and CBC modes of operation and PKCS7 padding.","archived":false,"fork":false,"pushed_at":"2022-04-25T21:48:56.000Z","size":8,"stargazers_count":12,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T00:34:22.841Z","etag":null,"topics":["cbc","cryptography","ecb","pkcs","xtea"],"latest_commit_sha":null,"homepage":"","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/simplito.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}},"created_at":"2015-10-11T18:45:14.000Z","updated_at":"2025-03-05T12:12:04.000Z","dependencies_parsed_at":"2022-08-11T19:40:21.724Z","dependency_job_id":null,"html_url":"https://github.com/simplito/xtea-js","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/simplito%2Fxtea-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplito%2Fxtea-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplito%2Fxtea-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplito%2Fxtea-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simplito","download_url":"https://codeload.github.com/simplito/xtea-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248351752,"owners_count":21089336,"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":["cbc","cryptography","ecb","pkcs","xtea"],"created_at":"2024-11-14T13:29:33.376Z","updated_at":"2025-04-11T06:19:13.198Z","avatar_url":"https://github.com/simplito.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"XTEA\n====\n\nA pure JavaScript implementation of [XTEA] block cipher with support \nfor [ECB] and [CBC] modes of operation.\n\nThe [PKCS#7] padding is used for processing data not alligned to 8-byte block size.\n\nThe [XTEA] cipher algorithm is very effective and is supported \nby PHP's [mcrypt] cryptographic extension (in contrast to XXTEA cipher) \nso you may find this module useful when you need interoperability \nbetween JS and PHP and don't need stronger cryptography.\n\nAPI\n---\n\nThis module exports four functions:\n\n### encrypt(msg, key, [mode=ecb], [iv], [skippad])\n\nEncrypts data using XTEA cipher using specified block cipher mode of operation\nand PKCS#7 padding.\n\n#### Params:\n\n* **Buffer** *msg* Message to encrypt\n* **Buffer** *key* 128-bit encryption key (16 bytes)\n* **string** *[mode=ecb]* Block cipher mode of operation (currently only 'ecb' or 'cbc')\n* **Buffer** *[iv]* Optional IV\n* **bool** *[skippad]* Skip PKCS#7 padding postprocessing\n\n#### Return:\n\n* **Buffer** \n\n### decrypt(msg, key, [mode=ecb], [iv], [skippad])\n\nDecrypts data using XTEA cipher using specified block cipher mode of operation\nand PKCS#7 padding.\n\n#### Params:\n\n* **Buffer** *msg* Ciphertext to decrypt\n* **Buffer** *key* 128-bit encryption key (16 bytes)\n* **string** *[mode=ecb]* Block cipher mode of operation (currently only 'ecb' or 'cbc')\n* **Buffer** *[iv]* Optional IV\n* **bool** *[skippad]* Skip PKCS#7 padding postprocessing\n\n#### Return:\n\n* **Buffer** \n\n### encryptBlock( block, key )\n\nEncrypts single block of data using XTEA cipher.\n\n#### Params:\n\n* **Buffer** *block* 64-bit (8-bytes) block of data to encrypt\n* **Buffer** *key* 128-bit (16-bytes) encryption key\n\n#### Return:\n\n* **Buffer** 64-bit of encrypted block\n\n\n### decryptBlock( block, key )\n\nDecrypts single block of data using XTEA cipher.\n\n#### Params:\n\n* **Buffer** *block* 64-bit (8-bytes) block of data to encrypt\n* **Buffer** *key* 128-bit (16-bytes) encryption key\n\n#### Return:\n\n* **Buffer** 64-bit of encrypted block\n\n\nExample usage\n-------------\n\n```javascript\nvar xtea = require('xtea');\n\nvar plaintext = new Buffer('Zażółć gęślą jaźń', 'utf8');\nvar key = new Buffer('33fd7bd6d85ddbe134c23fcb09c37e5a', 'hex');\nvar ciphertext = xtea.encrypt( plaintext, key );\n\nconsole.log( ciphertext.toString('hex') );\nconsole.log( xtea.decrypt( ciphertext, key ).toString() );\n```\n\nexpected output:\n\n```\nda9466824a7606cf8faa4bf462c667c1dc4a23cb508199fdd6689b5134640e09\nZażółć gęślą jaźń\n```\n\n\nExample PHP code\n----------------\n\n```php\nfunction xtea_encrypt($msg, $key, $mode, $iv) {\n    $pad = 8 - (strlen($msg) % 8);\n    $msg .= str_repeat(chr($pad), $pad);\n    return mcrypt_encrypt(MCRYPT_XTEA, $key, $msg, $mode, $iv);\n}\n\nfunction xtea_decrypt($msg, $key, $mode, $iv) {\n    $msg = mcrypt_decrypt(MCRYPT_XTEA, $key, $msg, $mode, $iv);\n    $pad = ord($msg[ strlen($msg) - 1 ]);\n    return substr($msg, 0, strlen($msg) - $pad);\n}\n```\n\n\nRunning tests\n-------------\n\nInstall dev dependencies and execute `npm run test`:\n\n    $ npm install -d\n    $ npm run test\n\n\n\\newpage\n\nLicense\n-------\n\nThe MIT License (MIT)\n\nCopyright (c) 2015 Sebastian Smyczynski, Simplito Inc.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n\n[XTEA]: https://en.wikipedia.org/wiki/XTEA\n[ECB]: https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#ECB\n[CBC]: https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#CBC\n[PKCS#7]: https://en.wikipedia.org/wiki/Padding_%28cryptography%29#PKCS7\n[mcrypt]: http://php.net/manual/en/book.mcrypt.php\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplito%2Fxtea-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplito%2Fxtea-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplito%2Fxtea-js/lists"}