How to use the asn1.js.bignum function in asn1

To help you get started, we’ve selected a few asn1 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 aws / aws-encryption-sdk-javascript / modules / serialize / src / ecdsa_signature.ts View on Github external
export function der2raw (derSignature: Uint8Array, { signatureCurve }: WebCryptoAlgorithmSuite): Uint8Array {
  /* Precondition: Do not attempt to RAW format if the suite does not support signing. */
  if (!signatureCurve) throw new Error('AlgorithmSuite does not support signing')

  const _keyLengthBytes = keyLengthBytes[signatureCurve]

  // A little more portable than Buffer.from, but not much
  const { r, s } = ECDSASignature.decode(new asn.bignum.BN(derSignature).toArrayLike(Buffer), 'der')

  const rLength = r.byteLength()
  const sLength = r.byteLength()

  return concatBuffers(
    new Uint8Array(_keyLengthBytes - rLength),
    r.toArrayLike(Uint8Array),
    new Uint8Array(_keyLengthBytes - sLength),
    s.toArrayLike(Uint8Array)
  )
}
github cloudflare / ipfs-ext / node_modules / pem-jwk / index.js View on Github external
var asn = require('asn1.js')
var factor = require('./factor')
var one = new asn.bignum(1)

function urlize(base64) {
  return base64.replace(/\+/g, '-')
    .replace(/\//g, '_')
    .replace(/=/g, '')
}

function hex2b64url(str) {
  return urlize(Buffer.from(str, 'hex').toString('base64'))
}

function fromPEM(data) {
  var text = data.toString().split(/(\r\n|\r|\n)+/g);
  text = text.filter(function(line) {
    return line.trim().length !== 0;
  });
github anvilresearch / webcrypto / src / asn1 / RSA.js View on Github external
function string2bn(str) {
  if (/^[0-9]+$/.test(str)) {
    return new asn.bignum(str, 10)
  }
  return base64url2bn(str)
}
github cloudflare / ipfs-ext / node_modules / pem-jwk / index.js View on Github external
function string2bn(str) {
  if (/^[0-9]+$/.test(str)) {
    return new asn.bignum(str, 10)
  }
  return base64url2bn(str)
}
github anvilresearch / webcrypto / src / asn1 / ECDSA.js View on Github external
/**
 * Package dependencies
 */
const asn = require('asn1.js')
//var factor = require('./factor')
const one = new asn.bignum(1)
const fs = require('fs')

/*
 * Test Data
 */
const public_test  = fs.readFileSync('./ecdsa_public.pem').toString("ascii")
const private_test = fs.readFileSync('./ecdsa_private.pem').toString("ascii")

function urlize(base64) {
  return base64.replace(/\+/g, '-')
    .replace(/\//g, '_')
    .replace(/=/g, '')
}

function hex2b64url(str) {
  return urlize(Buffer(str, 'hex').toString('base64'))
github anvilresearch / webcrypto / src / asn1 / RSA.js View on Github external
function base64url2bn(str) {
  return new asn.bignum(Buffer(str, 'base64'))
}
github cloudflare / ipfs-ext / node_modules / libp2p-crypto / src / keys / ecdh-browser.js View on Github external
function unmarshalPublicKey (curve, key) {
  const byteLen = curveLengths[curve]

  if (!key.slice(0, 1).equals(Buffer.from([4]))) {
    throw new Error('Invalid key format')
  }
  const x = new BN(key.slice(1, byteLen + 1))
  const y = new BN(key.slice(1 + byteLen))

  return {
    kty: 'EC',
    crv: curve,
    x: toBase64(x, byteLen),
    y: toBase64(y, byteLen),
    ext: true
  }
}
github cloudflare / ipfs-ext / node_modules / pem-jwk / index.js View on Github external
function base64url2bn(str) {
  return new asn.bignum(Buffer.from(str, 'base64'))
}