npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@safez/ngx-safez

v1.0.0

Published

Enhance your Angular applications with unparalleled cybersecurity by integrating the Angular Safez Interceptor, designed to work flawlessly from Angular 8 to the latest version. This advanced interceptor, powered by safez-cryptx, employs AES-CBC symmetric

Downloads

6

Readme

Overview of ngx-safez

ngx-safez is an interceptor library for Angular's HttpClient, designed to seamlessly encrypt and decrypt HTTP requests and responses. By applying robust encryption algorithms, it ensures the security of data in transit, providing a crucial layer of defense for web applications against unauthorized access. Integrating directly with Angular, ngx-safez offers developers a straightforward solution to bolster their application's security. It automatically handles the encryption of data before it leaves the client and decrypts incoming data, maintaining the protection of sensitive information throughout the transmission process. ngx-safez stands out for its high configurability, allowing developers to tailor encryption settings to fit the precise security needs of various applications, from those demanding stringent data protection to those requiring basic encryption enhancements.

  • Supports a variety of encryption standards to ensure secure data transmission.
  • Provides an added layer of security to help mitigate the risks associated with data breaches and cyber threats. Incorporating ngx-safez into Angular applications is simple and enhances security protocols without adding complexity to the development workflow.

Installation

To integrate ngx-safez into your project, use the following command:

npm install @safez/ngx-safez or yarn add @safez/ngx-safez

Setup and Configuration

Configure ngx-safez with your Angular application to encrypt and decrypt HTTP requests and responses effortlessly:

import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { NgxSafezService } from '@safez/ngx-safez';
@NgModule({
 declarations: [...],
 imports: [...],
 providers: [
   {
   provide: NGX_SAFEZ_CONFIG,
   useValue: {enableSafez: true, safezSaavi: true, cryptoType: 'field'}
   },
   {
     provide: HTTP_INTERCEPTORS,
     useClass: NgxSafezService,
     multi: true,
   },
 ],
})
export class AppModule {}

The optional values for NGX_SAFEZ_CONFIG are crypto type, configurable values are 'full', 'field', 'none'. When safezEnable is true, default value is full. When configured the safez, all your payload will be encrypted

Usage

With ngx-safez configured, all HTTP requests and responses managed by Angular's HttpClient will be automatically encrypted and decrypted.

Customizing Encryption per Request

You can specify the encryption type for individual requests using Angular's HttpHeaders:

import { HttpHeaders } from '@angular/common/http';
const headers = new HttpHeaders({
 'x-sz-token': JSON.stringify({ cryptoType: 'full', safezSaavi: 'dummysecretkeyab' })
});
// Use these headers in your HttpClient request

Examples:

  • Encrypting the entire request object:
const payload = { name: 'safez', product: 'security' };
const headers = new HttpHeaders({
 'x-sz-token': JSON.stringify({ cryptoType: 'full' })
});
this.http.post('http://example.url/api/post', payload, { headers }).subscribe();
// payload will be {encryptedData: 'encrypted string'}
  • Bypassing encryption for a request:
const config = { cryptoType: 'none' };
const headers = new HttpHeaders({
 'x-sz-token': JSON.stringify(config)
});
this.http.post('http://example.url/api/post', payload, { headers }).subscribe();
  • Encrypting specific fields within an object:
const payload = { name: 'safez', product: 'security' };
const config = { cryptoType: 'field' };
const headers = new HttpHeaders({
 'x-sz-token': JSON.stringify(config)
});
this.http.post('http://example.url/api/post', payload, { headers }).subscribe();
// The payload will have 'name' and 'product' values encrypted.

Handling Errors

Dealing with encrypted error messages requires diligent error handling, particularly for scenarios involving encrypted server responses. ngx-safez equips your application to intercept, decrypt, and process these error messages securely, ensuring a coherent and secure error handling strategy.

Best Practices for Secure Error Handling

  • Encryption Secret Management: Securely manage your encryption secrets, avoiding exposure in client-side code. Utilize secure storage solutions and restrict access to these secrets.
  • Optimize Encryption Use: Strategically employ encryption, considering both security needs and performance implications. Utilize HttpHeaders to selectively apply encryption, optimizing your application's performance and security.

Troubleshooting Common Encryption Issues

  • Encryption/Decryption Failures: Verify the consistency of encryption keys or secrets across the client and server. Discrepancies can lead to failed decryption and errors.
  • Interceptor Configuration: Ensure ngx-safez is correctly set up as an HTTP interceptor and that there are no conflicts with other interceptors in your Angular application.

Frequently Asked Questions (FAQ)

  • Can ngx-safez be used in any Angular application? Yes, ngx-safez is designed to integrate seamlessly with Angular's HttpClient, making it suitable for any Angular project.
  • How can I exclude specific requests from encryption? Utilize the x-sz-token header with a cryptoType of 'none' to bypass encryption for particular requests, allowing for flexible encryption application.