{"id":16416586,"url":"https://github.com/angeal185/rabbit-cipher","last_synced_at":"2026-05-16T02:38:05.020Z","repository":{"id":58236474,"uuid":"188039408","full_name":"angeal185/rabbit-cipher","owner":"angeal185","description":"rabbit 128bit cipher with poly1305 in javascript","archived":false,"fork":false,"pushed_at":"2019-05-29T02:41:40.000Z","size":57,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-06T18:13:00.635Z","etag":null,"topics":["browser","cipher","decryption","encryption","nodejs","poly1305","rabbit","rabbit-cipher"],"latest_commit_sha":null,"homepage":"https://angeal185.github.io/rabbit-cipher","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/angeal185.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":"2019-05-22T12:59:59.000Z","updated_at":"2023-06-29T15:46:45.000Z","dependencies_parsed_at":"2022-08-31T09:40:10.939Z","dependency_job_id":null,"html_url":"https://github.com/angeal185/rabbit-cipher","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/angeal185%2Frabbit-cipher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angeal185%2Frabbit-cipher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angeal185%2Frabbit-cipher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/angeal185%2Frabbit-cipher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/angeal185","download_url":"https://codeload.github.com/angeal185/rabbit-cipher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240466791,"owners_count":19805862,"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":["browser","cipher","decryption","encryption","nodejs","poly1305","rabbit","rabbit-cipher"],"created_at":"2024-10-11T07:09:36.227Z","updated_at":"2026-05-16T02:37:59.990Z","avatar_url":"https://github.com/angeal185.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rabbit-cipher\n\nrabbit 128bit cipher with poly1305\n\n\ndemo: https://angeal185.github.io/rabbit-cipher/\n\n### Installation\n\nnpm\n\n```sh\n$ npm install rabbit-cipher --save\n```\n\nbower\n\n```sh\n$ bower install rabbit-cipher\n```\n\ngit\n```sh\n$ git clone git@github.com:angeal185/rabbit-cipher.git\n```\n\n\n#### nodejs\n\n```js\n\nconst rabbit = require('rabbit-cipher');\n\n```\n\n#### browser\n\n```html\n\n\u003cscript src=\"./dist/rabbit.min.js\"\u003e\u003c/script\u003e\n\n```\n\n\n\n#### API\n\n```js\n\n/* encrypt */\n\n/**\n *  sync ~ encrypt data\n *  @param {string/byteArray/uint8Array} plain ~ data to be encrypted\n *  @param {string/byteArray/uint8Array} secret ~ encryption key\n *  @param {string} digest ~ encrypted data digest hex/bytes/binary/uint8/base64\n **/\n\nrabbit.encSync(plain, secret, digest)\n\n\n\n/**\n *  callback ~ encrypt data\n *  @param {string/byteArray/uint8Array} plain ~ data to be encrypted\n *  @param {string/byteArray/uint8Array} secret ~ encryption key\n *  @param {string} digest ~ encrypted data digest hex/bytes/binary/uint8/base64\n *  @param {function} cb ~ callback function(err,data)\n **/\n\nrabbit.enc(plain, secret, digest, cb)\n\n\n/**\n *  promise ~ encrypt data\n *  @param {string/byteArray/uint8Array} plain ~ data to be encrypted\n *  @param {string/byteArray/uint8Array} secret ~ encryption key\n *  @param {string} digest ~ encrypted data digest hex/bytes/binary/uint8/base64\n **/\nrabbit.encP(plain, secret, digest)\n\n\n/* decrypt */\n\n/**\n *  sync  ~ decrypt data\n *  @param {string/byteArray/uint8Array} ctext ~ data to be decrypted\n *  @param {string/byteArray/uint8Array} key ~ encryption key\n *  @param {string} digest ~ encrypted data digest hex/bytes/binary/uint8/base64\n **/\n\nrabbit.decSync(ctext, key, digest)\n\n\n/**\n *  callback  ~ decrypt data\n *  @param {string/byteArray/uint8Array} ctext ~ data to be decrypted\n *  @param {string/byteArray/uint8Array} key ~ encryption key\n *  @param {string} digest ~ encrypted data digest hex/bytes/binary/uint8/base64\n *  @param {function} cb ~ callback function(err,data)\n **/\n\nrabbit.dec(ctext, key, digest, cb)\n\n\n/**\n *  promise  ~ decrypt data\n *  @param {string/byteArray/uint8Array} ctext ~ data to be encrypted\n *  @param {string/byteArray/uint8Array} key ~ encryption key\n *  @param {string} digest ~ encrypted data digest hex/bytes/binary/uint8/base64\n **/\n\nrabbit.decP(ctext, key, digest)\n\n\n/* encrypt and sign with poly1305 */\n\n/**\n *  callback ~  encrypt and sign\n *  @param {string/byteArray/uint8Array} plain ~ data to encrypt\n *  @param {string/byteArray/uint8Array} key ~ encryption key\n *  @param {string/byteArray/uint8Array} skey ~ poly1305 key\n *  @param {string} digest ~ poly/data digest hex/bytes/binary/uint8/base64\n *  @param {function} cb ~ callback function(err,data)\n **/\n\nrabbit.encPoly(plain, key, skey, digest, cb)\n\n\n/**\n *  promise ~  encrypt and sign\n *  @param {string/byteArray/uint8Array} plain ~ data to encrypt\n *  @param {string/byteArray/uint8Array} key ~ encryption key\n *  @param {string/byteArray/uint8Array} skey ~ poly1305 key\n *  @param {string} digest ~ poly/data digest hex/bytes/binary/uint8/base64\n **/\n\nrabbit.encPolyP(plain, key, skey, digest)\n\n\n/* verify poly1305 and decrypt */\n\n/**\n *  callback ~  verify and decrypt\n *  @param {string/byteArray/uint8Array} ctext ~ data to decrypt\n *  @param {string/byteArray/uint8Array} key ~ decrypt key\n *  @param {string/byteArray/uint8Array} sig1 ~ poly signature\n *  @param {string/byteArray/uint8Array} sig2 ~ ctext signature\n *  @param {string} digest ~ poly/data digest hex/bytes/binary/uint8/base64\n *  @param {function} cb ~ callback function(err,data)\n **/\n\nrabbit.decPoly(ctext, key, sig1, sig2, digest, cb)\n\n\n/**\n *  promise ~  verify and decrypt\n *  @param {string/byteArray/uint8Array} ctext ~ data to decrypt\n *  @param {string/byteArray/uint8Array} key ~ decrypt key\n *  @param {string/byteArray/uint8Array} sig1 ~ poly signature\n *  @param {string/byteArray/uint8Array} sig2 ~ ctext signature\n *  @param {string} digest ~ poly/data digest hex/bytes/binary/uint8/base64\n **/\n\nrabbit.decPolyP(ctext, key, sig1, sig2, digest)\n\n\n\n/* poly1305 */\n\n/**\n *  callback ~ verify encrypted data\n *  @param {string/byteArray/uint8Array} ctext ~ cipher text\n *  @param {integer} len ~ cipher text length\n *  @param {string/byteArray/uint8Array} key ~ poly1305 key\n *  @param {string} digest ~ poly key digest hex/bytes/binary/uint8/base64\n *  @param {function} cb ~ callback function(err,data)\n **/\n\nrabbit.poly1305.sign(ctext, len, key, digest, cb)\n\n\n/**\n *  callback ~ verify encrypted data\n *  @param {string/byteArray/uint8Array} sig ~ first signature\n *  @param {string/byteArray/uint8Array} sig ~ second signature\n *  @param {string} digest ~ poly key digest hex/bytes/binary/uint8/base64\n *  @param {function} cb ~ callback function(err,data)\n **/\n\nrabbit.poly1305.verify(sig1, sig2, digest, cb)\n\n\n/**\n *  callback ~ verify encrypted data\n *  @param {string/byteArray/uint8Array} ctext ~ cipher text\n *  @param {integer} len ~ cipher text length\n *  @param {string/byteArray/uint8Array} key ~ poly1305 key\n *  @param {string} digest ~ poly key digest hex/bytes/binary/uint8/base64\n **/\n\nrabbit.poly1305.signSync(ctext, len, key, digest)\n\n\n/**\n *  sync ~ verify encrypted data\n *  @param {string/byteArray/uint8Array} sig1 ~ first signature\n *  @param {string/byteArray/uint8Array} sig2 ~ second signature\n *  @param {string} digest ~ poly key digest hex/bytes/binary/uint8/base64\n **/\n\nrabbit.poly1305.verifySync(sig1, sig2, digest)\n\n\n\n/* utils */\n\nrabbit.utils.u82s(Uint8Array) // Uint8Array to string\nrabbit.utils.s2u8(string) // string to Uint8Array\nrabbit.utils.b2s(Uint8Array) // byteArray to string\nrabbit.utils.s2b(string) // string to byteArray\nrabbit.utils.a2b(byteArray) // byteArray to binary\nrabbit.utils.b2a(byteArray) // binary to byteArray\nrabbit.utils.u82a(uint8Array) // uint8Array to byteArray\nrabbit.utils.h2u8(string) // hex to Uint8Array\nrabbit.utils.u82h(Uint8Array) // uint8Array to hex\nrabbit.utils.h2s(string) // hex to string\nrabbit.utils.s2h(string) // string to hex\nrabbit.utils.u8to16(Uint8Array) // Uint8Array to Uint16Array\nrabbit.utils.u16to8(Uint16Array) //  Uint16Array to Uint8Array\n\nrabbit.utils.secRand(string) // prng single\nrabbit.utils.randomBytes(length) // prng byteArray\n\nrabbit.utils.isUint8(i) // check Uint8Array\nrabbit.utils.isArray(i) // check array\nrabbit.utils.isString(i) // check string\n\n// demo\n\nconst utils = rabbit.utils,\ncl = console.log,\nce = console.error,\nsecret = 'secret',\nskey = utils.randomBytes(32),\ntext = 'test',\ndigest = 'hex';\n\n// enc/dec ~ sync\nlet sync = rabbit.encSync(text, secret, digest);\ncl(sync)\nsync = rabbit.decSync(sync, secret, digest)\ncl(sync === text)\n\n\n\n// enc/dec ~ callback\nrabbit.enc(text, secret, digest, function(err, ctext){\n  if(err){return ce(err)};\n  rabbit.dec(ctext, secret, digest, function(err, plain){\n    if(err){return ce(err)};\n    cl(plain === text);\n  });\n});\n\n\n// enc/dec ~ promise\nrabbit.encP(text, secret, digest).then(function(ctext){\n  rabbit.decP(ctext, secret, digest).then(function(plain){\n      cl(plain === text);\n  }).catch(function(err){\n    ce(err)\n  })\n}).catch(function(err){\n  ce(err)\n})\n\n// encrypt/decrypt with poly1305 ~ callback\nrabbit.encPoly(text, secret, skey, digest, function(err, res){\n  if(err){return ce(err)};\n\n  let verify = rabbit.poly1305.signSync(res.ctext, res.ctext.length, skey, digest);\n\n  rabbit.decPoly(res.ctext, secret, res.sig, verify, digest, function(err, plain){\n    if(err){return ce(err)};\n    cl(plain)\n  });\n\n});\n\n// encrypt/decrypt with poly1305 ~ promise\nrabbit.encPolyP(text, secret, skey, digest).then(function(res){\n  let verify = rabbit.poly1305.signSync(res.ctext, res.ctext.length, skey, digest);\n  rabbit.decPolyP(res.ctext, secret, res.sig, verify, digest).then(function(plain){\n    cl(plain)\n  }).catch(function(err){\n    ce(err)\n  })\n}).catch(function(err){\n  ce(err)\n})\n\n\n// poly1305\nrabbit.enc(text, secret, digest, function(err, ctext){\n  if(err){return ce(err)};\n\n  // poly1305 ~ callback\n  rabbit.poly1305.sign(ctext, ctext.length, skey, digest, function(err, sig){\n\n    // poly1305 ~ sync\n    let verify = rabbit.poly1305.signSync(ctext, ctext.length, skey, digest);\n\n    rabbit.poly1305.verify(sig, verify, digest, function(err, ver){\n      if(ver){\n        rabbit.dec(ctext, secret, digest, function(err, plain){\n          if(err){return ce(err)};\n          cl(plain);\n        });\n      } else {\n        ce('rabbit poly1305 authentication failure')\n      }\n    });\n\n  })\n});\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangeal185%2Frabbit-cipher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fangeal185%2Frabbit-cipher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fangeal185%2Frabbit-cipher/lists"}