New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

ec-pem

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ec-pem

Enables `crypto.sign` and `crypto.verify` using `crypto.createECDH` generated keys

latest
Source
npmnpm
Version
0.18.0
Version published
Weekly downloads
125
-1.57%
Maintainers
1
Weekly downloads
 
Created
Source

ec_pem

Enables crypto.sign and crypto.verify using crypto.createECDH generated keys

Use

const crypto = require('crypto');
const ec_pem = require('ec-pem');

let alice_pem_private, alice_pem_public;
{
  let curve = 'secp521r1'
  let alice = crypto.createECDH(curve);
  alice.generateKeys();
  alice = ec_pem(alice, curve);

  alice_pem_private = alice.encodePrivateKey();
  // console.log(alice_pem_private);

  alice_pem_public = alice.encodePublicKey();
  // console.log(alice_pem_public);
}


const data = Buffer.from('a message to sign');

let signature;
{
  const sign = crypto.createSign('sha256');
  sign.update(data);
  signature = sign.sign(alice_pem_private);
  // console.log({signature})
}


{
  const verify = crypto.createVerify('sha256');
  verify.update(data);
  const matched = verify.verify(alice_pem_public, signature);
  // console.log({matched})
  if (!matched)
    throw new Error("Verification failed");
}

Use ec_pem/cert

const https = require('https');
const ec_pem = require('ec-pem');
const ec_cert = require('ec-pem/cert');

const tls_options = ec_cert.createSelfSignedCertificate('example.com', 
    { ec: ec_pem.generate('prime256v1'),
      days: 30, altNames: ['example.com', 'www.example.com', '1.234.56.255'] })

demo_https_server(tls_options)



function demo_https_server(tls_options) {
  let svr = tls_options
    .then(options => https.createServer(options) )
    .then(svr => {
      svr.on('secureConnection', sock => console.log("New secure connection"));
      svr.on('request', (req,res) => {
        res.writeHead(200);
        res.end('hello world\n');
      });
      return svr })
    .then(svr => new Promise((resolve, reject) =>
        svr.listen(8443, '127.0.0.1',
          (err) => err ? reject(err) : resolve(svr))))

  svr.then(() =>
    https.get(
      {hostname: '127.0.0.1', port:8443, pathname:'/', rejectUnauthorized: false},
      res => { console.log(res.statusCode) }))
}

Use ec_pem/local_cert

const https = require('https');
const ec_localcert = require('ec-pem/local_cert');

const tls_options = ec_localcert('tls_local.json')

demo_https_server(tls_options)

or

const https = require('https');
const ec_localcert = require('ec-pem/local_cert');

const tls_options = ec_localcert('tls_local.json', ({ec_cert, ec_pem}) =>
  ec_cert.createSelfSignedCertificate('localhost.dev', {
    ec: ec_pem.generate('prime256v1'),
    days: 3660, // 10 years
    altNames: ['localhost.dev', 'localhost', '127.0.0.1'],
  }))

demo_https_server(tls_options)

Keywords

ECDH

FAQs

Package last updated on 21 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts