@4us-dev/crypto

Utility classes to assist developers during software development

Usage no npm install needed!

<script type="module">
  import 4usDevCrypto from 'https://cdn.skypack.dev/@4us-dev/crypto';
</script>

README

4us-dev crypto

Quality Gate Status Coverage Code Smells Vulnerabilities Maintainability Rating Security Rating

Build and Tests npm-package issues dependencies dev-dependencies downloads size license

Install with npm

npm i @4us-dev/crypto

Introduction

@4us-dev/crypto is a lib to help developers with encryption and encoding.

Usage

Base64

import { base64 } from '@4us-dev/crypto';

encode

base64.encode('teste+encode+');
// output
// dGVzdGUrZW5jb2RlKw==

decode

base64.decode('dGVzdGUrZW5jb2RlKw==');
// output
// teste+encode+

Base64Url

import { base64Url } from '@4us-dev/crypto';

encode

base64Url.encode('teste+encode+');
// output
// dGVzdGUrZW5jb2RlKw

decode

base64Url.decode('dGVzdGUrZW5jb2RlKw');
// output
// teste+encode+

sha256

import { sha256 } from '@4us-dev/crypto';

default encoding is hex

sha256('4us dev');
// output
// 9c8813f0ca966480ebd17668f7850c85930e9a5e2425a71d9b1125c9026edf3d

defining output encode

sha256('4us dev', 'base64');
// output
// nIgT8MqWZIDr0XZo94UMhZMOml4kJacdmxElyQJu3z0=

PKCE

Generate code verifier and code challenge for OAuth with PKCE.

import { pkce } from '@4us-dev/crypto';

codeVerifierGenerator

const codeVerifier = pkce.codeVerifierGenerator();
// output example
// FVMq~J2BfdXm2cEOEtlKQTGNRjYQ8VYA6OETFrW3A915~8dbktXkSwtVbZnUUStkApwZjcIWCYV.OiITpYNXpuWGBEM1.oFxT7ZizzoQ0OE81ZAOIU1JCwXMxmCQtyL2

codeChallengeGenerator

pkce.codeChallengeGenerator(codeVerifier);
// output example
// Ae8fgMraIhwQDPladfacB-s6Oh4Hzs34SXLQmiyci98