{"_id":"fernet-ts","_rev":"2-b49410f626b5dffbd449f680ac920ebd","name":"fernet-ts","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"fernet-ts","repository":{"type":"git","url":"git+https://github.com/zoran-php/fernet-ts.git"},"version":"1.0.0","description":"Fernet algorithm implementation written in Typescript using Web Crypto API","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npx tsc","test":"jest","format":"prettier --write \"src/**/*.ts\"","lint":"eslint -c .eslintrc.json"},"keywords":["fernet","cryptography","web","typescript","crypto","api","subtle","cipher","symmetric","encryption","decryption","key"],"author":{"name":"Zoran Davidovic"},"license":"ISC","devDependencies":{"@babel/core":"^7.21.0","@babel/preset-env":"^7.20.2","@babel/preset-typescript":"^7.21.0","@inrupt/jest-jsdom-polyfills":"^1.6.2","@jest/globals":"^29.4.3","@testing-library/jest-dom":"^5.16.5","@types/jest":"^29.4.0","@types/node":"^18.14.4","@typescript-eslint/eslint-plugin":"^5.55.0","babel-jest":"^29.4.3","eslint":"^8.36.0","eslint-config-airbnb":"^19.0.4","eslint-config-prettier":"^8.7.0","eslint-config-standard-with-typescript":"^34.0.1","eslint-plugin-import":"^2.27.5","eslint-plugin-jsx-a11y":"^6.7.1","eslint-plugin-n":"^15.6.1","eslint-plugin-prettier":"^4.2.1","eslint-plugin-promise":"^6.1.1","eslint-plugin-react":"^7.32.2","eslint-plugin-react-hooks":"^4.6.0","jest":"^29.4.3","jest-environment-jsdom":"^29.5.0","prettier":"^2.8.4","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"^4.9.5"},"gitHead":"7e6c2a705cc6935c375b53df22deec9340bfb8b7","bugs":{"url":"https://github.com/zoran-php/fernet-ts/issues"},"homepage":"https://github.com/zoran-php/fernet-ts#readme","_id":"fernet-ts@1.0.0","_nodeVersion":"16.13.1","_npmVersion":"8.1.2","dist":{"integrity":"sha512-Z4kS/HU+s9fQ6rMh+GsL7jGnRbJQp/sscOrEI8Qq9h/BpZ3egBJZt65P9DkiFCO1hi1pZdd0r90r3zw/DzmvZg==","shasum":"ed1bbfa7f00bc5dc04af6c44141f0c02ae07377a","tarball":"https://registry.npmjs.org/fernet-ts/-/fernet-ts-1.0.0.tgz","fileCount":27,"unpackedSize":67950,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCID0gw3vYDZFXCWazs6kcCaxQ0w7cQWLnAzkGyARmb1I/AiAULT+RjNp5Yn6TUtCyPlpPv+OT/CtgHxV7MST4iP+H5A=="}]},"_npmUser":{"name":"dawndavidson","email":"zorandavidovic@outlook.com"},"directories":{},"maintainers":[{"name":"dawndavidson","email":"zorandavidovic@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fernet-ts_1.0.0_1683384750659_0.34747265989139464"},"_hasShrinkwrap":false},"1.0.1":{"name":"fernet-ts","repository":{"type":"git","url":"git+https://github.com/zoran-php/fernet-ts.git"},"version":"1.0.1","description":"Fernet algorithm implementation written in Typescript using Web Crypto API","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npx tsc","test":"jest","format":"prettier --write \"src/**/*.ts\"","lint":"eslint -c .eslintrc.json"},"keywords":["fernet","cryptography","web","typescript","crypto","api","subtle","cipher","symmetric","encryption","decryption","key"],"author":{"name":"Zoran Davidovic"},"license":"ISC","devDependencies":{"@babel/core":"^7.21.0","@babel/preset-env":"^7.20.2","@babel/preset-typescript":"^7.21.0","@inrupt/jest-jsdom-polyfills":"^1.6.2","@jest/globals":"^29.4.3","@testing-library/jest-dom":"^5.16.5","@types/jest":"^29.4.0","@types/node":"^18.14.4","@typescript-eslint/eslint-plugin":"^5.55.0","babel-jest":"^29.4.3","eslint":"^8.36.0","eslint-config-airbnb":"^19.0.4","eslint-config-prettier":"^8.7.0","eslint-config-standard-with-typescript":"^34.0.1","eslint-plugin-import":"^2.27.5","eslint-plugin-jsx-a11y":"^6.7.1","eslint-plugin-n":"^15.6.1","eslint-plugin-prettier":"^4.2.1","eslint-plugin-promise":"^6.1.1","eslint-plugin-react":"^7.32.2","eslint-plugin-react-hooks":"^4.6.0","jest":"^29.4.3","jest-environment-jsdom":"^29.5.0","prettier":"^2.8.4","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"^4.9.5"},"gitHead":"b17c5a225864f0a784214c0321baaa2fd645f81b","bugs":{"url":"https://github.com/zoran-php/fernet-ts/issues"},"homepage":"https://github.com/zoran-php/fernet-ts#readme","_id":"fernet-ts@1.0.1","_nodeVersion":"16.13.1","_npmVersion":"8.1.2","dist":{"integrity":"sha512-rsqn4jqLSEuiykj8bxOCODY47I9h75dSus6lbjmlJKcI44MOmrovgCTsXp9eZxy2ofmp9WgolK/CI9k7uBReBQ==","shasum":"289d95f7f199999bbefb6daa2bb4d1c0cde60e34","tarball":"https://registry.npmjs.org/fernet-ts/-/fernet-ts-1.0.1.tgz","fileCount":27,"unpackedSize":67946,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHzB8K2DLEuzk2zy7N6gkwSqxgo9UP0ewGPtXm3iIxL0AiBurGFZvyq04/q4yjbzjKX4Fp5kxaGUW/MVkQIVQTt61Q=="}]},"_npmUser":{"name":"dawndavidson","email":"zorandavidovic@outlook.com"},"directories":{},"maintainers":[{"name":"dawndavidson","email":"zorandavidovic@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fernet-ts_1.0.1_1683384941257_0.15242417984983092"},"_hasShrinkwrap":false},"1.0.2":{"name":"fernet-ts","repository":{"type":"git","url":"git+https://github.com/zoran-php/fernet-ts.git"},"version":"1.0.2","description":"Fernet algorithm implementation written in Typescript using Web Crypto API","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"npx tsc","test":"jest","format":"prettier --write \"src/**/*.ts\"","lint":"eslint -c .eslintrc.json"},"keywords":["fernet","cryptography","web","typescript","crypto","api","subtle","cipher","symmetric","encryption","decryption","key"],"author":{"name":"Zoran Davidovic"},"license":"ISC","devDependencies":{"@babel/core":"^7.21.0","@babel/preset-env":"^7.20.2","@babel/preset-typescript":"^7.21.0","@inrupt/jest-jsdom-polyfills":"^1.6.2","@jest/globals":"^29.4.3","@testing-library/jest-dom":"^5.16.5","@types/jest":"^29.4.0","@types/node":"^18.14.4","@typescript-eslint/eslint-plugin":"^5.55.0","babel-jest":"^29.4.3","eslint":"^8.36.0","eslint-config-airbnb":"^19.0.4","eslint-config-prettier":"^8.7.0","eslint-config-standard-with-typescript":"^34.0.1","eslint-plugin-import":"^2.27.5","eslint-plugin-jsx-a11y":"^6.7.1","eslint-plugin-n":"^15.6.1","eslint-plugin-prettier":"^4.2.1","eslint-plugin-promise":"^6.1.1","eslint-plugin-react":"^7.32.2","eslint-plugin-react-hooks":"^4.6.0","jest":"^29.4.3","jest-environment-jsdom":"^29.5.0","prettier":"^2.8.4","ts-jest":"^29.0.5","ts-node":"^10.9.1","typescript":"^4.9.5"},"gitHead":"47e6e783fec2c2570f86d4cbb3870a472da27b86","bugs":{"url":"https://github.com/zoran-php/fernet-ts/issues"},"homepage":"https://github.com/zoran-php/fernet-ts#readme","_id":"fernet-ts@1.0.2","_nodeVersion":"16.13.1","_npmVersion":"8.1.2","dist":{"integrity":"sha512-Ej23Dg7GhI3qNPMRNcxTKFLTTl0mb+J/P0fh9DmGVoYGzr9mXqcvvEiAYidEOof1NGHqyUtsxbqHlrXbyS3LhA==","shasum":"d0f0fbc33dfca32ea9b868635246540ebb5fa029","tarball":"https://registry.npmjs.org/fernet-ts/-/fernet-ts-1.0.2.tgz","fileCount":27,"unpackedSize":68132,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCTFo9bp3ggvm5Jt5mdVNLZI5ZJX/Ls809u3+ZpICVMHQIhANxSVg32yBu+iJShYiZW49gKoJ8o3eYdtTa/Vwt57bQk"}]},"_npmUser":{"name":"dawndavidson","email":"zorandavidovic@outlook.com"},"directories":{},"maintainers":[{"name":"dawndavidson","email":"zorandavidovic@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fernet-ts_1.0.2_1683403869423_0.24232650350118434"},"_hasShrinkwrap":false}},"time":{"created":"2023-05-06T14:52:30.658Z","1.0.0":"2023-05-06T14:52:30.837Z","modified":"2023-05-06T20:11:09.791Z","1.0.1":"2023-05-06T14:55:41.413Z","1.0.2":"2023-05-06T20:11:09.689Z"},"maintainers":[{"name":"dawndavidson","email":"zorandavidovic@outlook.com"}],"description":"Fernet algorithm implementation written in Typescript using Web Crypto API","homepage":"https://github.com/zoran-php/fernet-ts#readme","keywords":["fernet","cryptography","web","typescript","crypto","api","subtle","cipher","symmetric","encryption","decryption","key"],"repository":{"type":"git","url":"git+https://github.com/zoran-php/fernet-ts.git"},"author":{"name":"Zoran Davidovic"},"bugs":{"url":"https://github.com/zoran-php/fernet-ts/issues"},"license":"ISC","readme":"# fernet-ts\n\nFernet algorithm implementation written in Typescript (Web version only, not compatible with Node.js).\n\nThis implementation is interoperable with Python version of Fernet.\nEncrypted text in this Typescript implementation can be decrypted using Python Fernet library and vice versa.\n\n## Installation\n\nUse the package manager [npm](https://github.com/npm/cli) to install [fernet-ts](https://www.npmjs.com/package/fernet-ts).\n\n```bash\nnpm i fernet-ts\n```\n\n## Usage\n\n```typescript\nimport { Fernet } from 'fernet-ts';\n\n// Generate secret key\n// Returns 32-byte long base64url encoded string\n// Example: \"Brxd-7fAiRQFYz2eI81ZNzCzJwf7BjAsMjtx-_KH5wo=\"\nconst secret = Fernet.generateSecret();\n\n// some random text to encrypt\nconst message = \"This is a top secret message!\";\n\n// create new Fernet instance\nconst f = await Fernet.getInstance(secret);\n\n// encrypt message\n// returns base64url encoded string\n// Example: \"gAAAAABkASMLGab74DqnryApsIrMxLsb5lvRUMnc6YzNYMEt79UVUOBQyqhqGiQu7G9s9h9wnDyWBa78odzUCJvx9jJi5ENrqAL_T6xEgRTmn43mtXOQ42Y=\"\nconst token = await f.encrypt(message);\n\n// decrypt token and get message\n// returns origin plain text message\n// Example: \"This is a top secret message!\"\nconst plainText = await f.decrypt(token);\n\n// You can also use static methods for encryption/decryption\nconst fernetToken = await Fernet.encrypt(message, secret);\nconst decryptedText = await Fernet.decrypt(fernetToken, secret);\n\n```\n\n## Fernet Spec\n\nThis document describes version 0x80 (currently the only\nversion) of the fernet format.\n\nConceptually, fernet takes a user-provided *message* (an arbitrary\nsequence of bytes), a *key* (256 bits === 32 bytes), and the current\ntime, and produces a *token*, which contains the message in a form\nthat can't be read or altered without the key.\n\nTo facilitate convenient interoperability, this spec defines the\nexternal format of both tokens and keys.\n\nAll encryption in this version is done with AES 128 in CBC mode.\n\nAll base 64 encoding is done with the \"URL and Filename Safe\"\nvariant, defined in [RFC 4648](http://tools.ietf.org/html/rfc4648#section-5) as \"base64url\".\n\n## Key Format\n\nA fernet *key* is the base64url encoding of the following\nfields:\n\n```text\n    Signing-key ‖ Encryption-key\n```\n\n- *Signing-key*, 128 bits\n- *Encryption-key*, 128 bits\n\n## Token Format\n\nA fernet *token* is the base64url encoding of the\nconcatenation of the following fields:\n\n```text\n    Version ‖ Timestamp ‖ IV ‖ Ciphertext ‖ HMAC\n```\n\n- *Version*, 8 bits (1 byte)\n- *Timestamp*, 64 bits (8 bytes)\n- *IV*, 128 bits (16 bytes)\n- *Ciphertext*, variable length, multiple of 128 bits (16 bytes)\n- *HMAC*, 256 bits (32 bytes)\n\nFernet tokens are not self-delimiting. It is assumed that the\ntransport will provide a means of finding the length of each\ncomplete fernet token.\n\n## Token Fields\n\n### Version\n\nThis field denotes which version of the format is being used by\nthe token. Currently there is only one version defined, with the\nvalue 128 (0x80).\n\n### Timestamp\n\nThis field is a 64-bit unsigned big-endian integer. It records the\nnumber of seconds elapsed between January 1, 1970 UTC and the time\nthe token was created.\n\n### IV\n\nThe 128-bit Initialization Vector used in AES encryption and\ndecryption of the Ciphertext.\n\nWhen generating new fernet tokens, the IV must be chosen uniquely\nfor every token. With a high-quality source of entropy, random\nselection will do this with high probability.\n\n### Ciphertext\n\nThis field has variable size, but is always a multiple of 128\nbits, the AES block size. It contains the original input message,\npadded and encrypted.\n\n### HMAC\n\nThis field is the 256-bit SHA256 HMAC, under signing-key, of the\nconcatenation of the following fields:\n\n```text\n    Version ‖ Timestamp ‖ IV ‖ Ciphertext\n```\n\nNote that the HMAC input is the entire rest of the token verbatim,\nand that this input is *not* base64url encoded.\n\n## Generating\n\nGiven a key and message, generate a fernet token with the\nfollowing steps, in order:\n\n1. Record the current time for the timestamp field.\n2. Choose a unique IV.\n3. Construct the ciphertext:\n   1. Pad the message to a multiple of 16 bytes (128 bits) per [RFC\n   5652, section 6.3](http://tools.ietf.org/html/rfc5652#section-6.3).\n   This is the same padding technique used in [PKCS #7\n   v1.5](http://tools.ietf.org/html/rfc2315#section-10.3) and all\n   versions of SSL/TLS (cf. [RFC 5246, section\n   6.2.3.2](http://tools.ietf.org/html/rfc5246#section-6.2.3.2) for\n   TLS 1.2).\n   2. Encrypt the padded message using AES 128 in CBC mode with\n   the chosen IV and user-supplied encryption-key.\n4. Compute the HMAC field as described above using the\nuser-supplied signing-key.\n5. Concatenate all fields together in the format above.\n6. base64url encode the entire token.\n\n## Verifying\n\nGiven a key and token, to verify that the token is valid and\nrecover the original message, perform the following steps, in\norder:\n\n1. base64url decode the token.\n2. Ensure the first byte of the token is 0x80.\n3. If the user has specified a maximum age (or \"time-to-live\") for\nthe token, ensure the recorded timestamp is not too far in the\npast.\n4. Recompute the HMAC from the other fields and the user-supplied\nsigning-key.\n5. Ensure the recomputed HMAC matches the HMAC field stored in the\ntoken, using a constant-time comparison function.\n6. Decrypt the ciphertext field using AES 128 in CBC mode with the\nrecorded IV and user-supplied encryption-key.\n7. Unpad the decrypted plaintext, yielding the original message.\n","readmeFilename":"README.md"}