![]() ![]() On the browser, Javascript offers two functions for decoding and encoding base64 strings, btoa() and atob(), see Base64. Next we create our encryption class by updating encryption.ts as follows: gitignore file to prevent our environmental variables from getting into source control for security reasons. env.example file to place all the keys of the. env file to store our environmental variables and. Next, we need create our src directory and then our library file as follows: $ mkdir src We also need to install dotenv to load environment variables from an. ![]() We will be using the Buffer class to write and read unsigned 64-bit integers because JavaScript has a maximum safe integer of 53 bits and our library must be able to handle 64-bit big endian especially when we need to encrypt and decrypt large integers such as phone numbers. This module provides us cryptographic functionalities like OpenSSL's hash, cipher, decipher, sign, verify and HMAC functions. Note that the NPM's crypto module has been deprecated as it is now a built-in Node module. Next, we need to install some additional packages for our library. This will generate an initial **tsconfig.json** file at the root of the project with possible configuration options, with non-essential options commented out. We initialize a tsconfig.json file as follows: $ yarn tsc -init -rootDir src -outDir dist $ yarn add -D ts-node we need to add a tsconfig.json file to the root of our project for our Typescript configuration. Next, we need to install **ts-node** to enable us execute Typescript files without needing to compile them and also. ![]() This is because we will be compiling our Typescript code into JavaScript for our production build. Next, we need to install Typescript as a dev dependency. Initialize package.json for the project: $ yarn init -y Next, we create our project folder and set up typescript: $ mkdir encrypt-decrypt-library I also prefer using NVM to manage my Node versions. You also need to have npm and/or yarn globally installed.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |