1.0.2 • Published 5 years ago

ngx-secure-cookies v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

NgxSecureCookies

This library was generated with Angular CLI version 8.2.0.

Installation

npm i ngx-secure-cookies --save

Then...

Providing the service in app

  • you can import in app.module.ts or in your custom module to use as singleton service / shared service
  • you can import in component level.

Usage

import { Component } from '@angular/core';
import {NgxSecureCookiesService} from 'ngx-secure-cookies'

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
  providers: [NgxSecureCookiesService]
})
export class AppComponent {
  title = 'cookies-test';
  constructor(
    private cookie:NgxSecureCookiesService,
  ){

    var key = this.cookie.generateKey("128/32","hello");
    
    this.cookie.encrypt("test","hello test",key);

    var result = this.cookie.decrypt("test",key)

    this.cookie.delete("test)

    this.cookie.deleteAllCookies("/")

  }

}

generateKey(keySize:string, val:string)

var key = this.cookie.generateKey("128/32","hello");
  • it will generate a key which is used to encrypt or decrypt or else you can provide your own keys.
  • First parameter should be keySize. available keySize are '128/32','256/32'.'512/32'.
  • Second parameter will be any user defined string.

encrypt(cookieName:string, val:string, key:string)

this.cookie.encrypt("test","hello test",key);
  • it will encrypt the message or value. it will use AES encryption algorithm as of now.
  • it will automatically set the cookie also.

decrypt(cookieName:string, key:string)

var result = this.cookie.decrypt("test",key)
  • it will decrypt() the encrypted key .you just have to pass the cookie name and the key (which is given at encryption).

delete(cookieName:string)

this.cookie.delete("test")
  • delete the specified cookie from browser cookies.

deleteAllCookies(cookiePath:string)

this.cookie.deleteAllCookies("/")
  • deletes all the cookies in the given path

    Note

  • Dont use different keys for encryption and decryption. the key used in encryption sholud be same for decryption.
1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago