@cambridge-blockchain/ngx-crypto
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Ngx Crypto Service

npm version

Getting Started

In order to use this library in your angular project install it as follows.

$ npm install @cambridge-blockchain/crypto-lib
$ npm install @cambridge-blockchain/ngx-crypto

Import the crypto service as follows

import { NgxCryptoService } from "@cambridge-blockchain/ngx-crypto";

NgxCryptoService Function Signatures

  publicKeyBase64(): Observable<string>

  async encryptAttribute(
    attributeValue: ArrayBuffer,
    encSymKey: string
  ): Promise<EncryptedData>

  async decryptAttribute(
    encAttributeValue: ArrayBuffer,
    encSymKey: string,
    iv: Uint8Array
  ): Promise<ArrayBuffer>

  async decryptStringAttribute(
    encAttributeValue: string,
    encSymKey: string,
    iv: Uint8Array
  ): Promise<ArrayBuffer>

  async computeHash(attributeValue: ArrayBuffer): Promise<Hash>

  async verifyHash(hash: Hash, attributeValue: ArrayBuffer): Promise<boolean>

Example Use

import { Component, OnInit } from "@angular/core";
import { NgxCryptoService } from "@cambridge-blockchain/ngx-crypto";
import { Hash } from "@cambridge-blockchain/crypto-lib";

@Component({
  selector: "personal",
  templateUrl: "./personal.component.html",
})
export class PersonalComponent implements OnInit {
  constructor(crypto: NgxCryptoService) {
    console.log("crypto service", crypto);
  }

  ngOnInit() {
    const ab = new ArrayBuffer(1024);
    crypto.computeHash(ab).then((hash: Hash) => {
      console.log("computed hash", hash);

      crypto.verifyHash(hash, ab).then((valid) => {
        console.log("is hash valid?", valid);
      });
    });
  }
}

Package Sidebar

Install

npm i @cambridge-blockchain/ngx-crypto

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

96.7 kB

Total Files

24

Last publish

Collaborators

  • obale