How to use the qz-tray.security function in qz-tray

To help you get started, we’ve selected a few qz-tray examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github qzind / tray / assets / signing / sign-message.ts View on Github external
import { Component } from '@angular/core';
import * as qz from 'qz-tray';
import { sha256 } from 'js-sha256';
import { KJUR, KEYUTIL, stob64, hextorstr } from 'jsrsasign';

qz.security.setCertificatePromise((resolve, reject) => {
 fetch("assets/digital-certificate.txt", {cache: 'no-store', headers: {'Content-Type': 'text/plain'}})
  .then(data => resolve(data.text()));
});

/*
 * Client-side using jsrsasign
 */
qz.security.setSignatureAlgorithm("SHA512"); // Since 2.1
qz.security.setSignaturePromise(hash => {
 return (resolve, reject) => {
  fetch("assets/private-key.pem", {cache: 'no-store', headers: {'Content-Type': 'text/plain'}})
   .then(wrapped => wrapped.text())
   .then(data => {
     var pk = KEYUTIL.getKey(data);
     var sig = new KJUR.crypto.Signature({"alg": "SHA512withRSA"}); // Use "SHA1withRSA" for QZ Tray 2.0 and older
     sig.init(pk);
     sig.updateString(hash);
     var hex = sig.sign();
     console.log("DEBUG: \n\n" + stob64(hextorstr(hex)));
     resolve(stob64(hextorstr(hex)));
   })
   .catch(err => console.error(err));
  };
});
github qzind / tray / assets / signing / sign-message.ts View on Github external
// # functions.                                            #
// #                                                       #
// # Organizations that do not protect against un-         #
// # authorized signing will be black-listed to prevent    #
// # software piracy.                                      #
// #                                                       #
// # -QZ Industries, LLC                                   #
// #                                                       #
// #########################################################

import { Component } from '@angular/core';
import * as qz from 'qz-tray';
import { sha256 } from 'js-sha256';
import { KJUR, KEYUTIL, stob64, hextorstr } from 'jsrsasign';

qz.security.setCertificatePromise((resolve, reject) => {
 fetch("assets/digital-certificate.txt", {cache: 'no-store', headers: {'Content-Type': 'text/plain'}})
  .then(data => resolve(data.text()));
});

/*
 * Client-side using jsrsasign
 */
qz.security.setSignatureAlgorithm("SHA512"); // Since 2.1
qz.security.setSignaturePromise(hash => {
 return (resolve, reject) => {
  fetch("assets/private-key.pem", {cache: 'no-store', headers: {'Content-Type': 'text/plain'}})
   .then(wrapped => wrapped.text())
   .then(data => {
     var pk = KEYUTIL.getKey(data);
     var sig = new KJUR.crypto.Signature({"alg": "SHA512withRSA"}); // Use "SHA1withRSA" for QZ Tray 2.0 and older
     sig.init(pk);

qz-tray

Connects a web client to the QZ Tray software. Enables printing and device communication from javascript.

LGPL-2.1
Latest version published 4 months ago

Package Health Score

77 / 100
Full package analysis