How to use the libp2p-crypto/src/keys/rsa-class.RsaPublicKey function in libp2p-crypto

To help you get started, we’ve selected a few libp2p-crypto 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 richardschneider / ipfs-encryption / test / peerid.js View on Github external
it('encoded public key with JWT', (done) => {
    const jwk = {
      kty: 'RSA',
      n: 'tkiqPxzBWXgZpdQBd14o868a30F3Sc43jwWQG3caikdTHOo7kR14o-h12D45QJNNQYRdUty5eC8ItHAB4YIH-Oe7DIOeVFsnhinlL9LnILwqQcJUeXENNtItDIM4z1ji1qta7b0mzXAItmRFZ-vkNhHB6N8FL1kbS3is_g2UmX8NjxAwvgxjyT5e3_IO85eemMpppsx_ZYmSza84P6onaJFL-btaXRq3KS7jzXkzg5NHKigfjlG7io_RkoWBAghI2smyQ5fdu-qGpS_YIQbUnhL9tJLoGrU72MufdMBZSZJL8pfpz8SB9BBGDCivV0VpbvV2J6En26IsHL_DN0pbIw',
      e: 'AQAB',
      alg: 'RS256',
      kid: '2011-04-29'
    }
    // console.log('jwk', jwk)
    const rsa = new rsaClass.RsaPublicKey(jwk)
    // console.log('rsa', rsa)
    rsa.hash((err, keyId) => {
      // console.log('err', err)
      // console.log('keyId', keyId)
      // console.log('id decoded', multihash.decode(keyId))
      const kids = multihash.toB58String(keyId)
      // console.log('id', kids)
      expect(kids).to.equal(peer.toB58String())
      done()
    })
  })
github richardschneider / ipfs-encryption / test / peerid.js View on Github external
it('encoded public key with DER', (done) => {
    const jwk = rsaUtils.pkixToJwk(publicKeyDer)
    // console.log('jwk', jwk)
    const rsa = new rsaClass.RsaPublicKey(jwk)
    // console.log('rsa', rsa)
    rsa.hash((err, keyId) => {
      // console.log('err', err)
      // console.log('keyId', keyId)
      // console.log('id decoded', multihash.decode(keyId))
      const kids = multihash.toB58String(keyId)
      // console.log('id', kids)
      expect(kids).to.equal(peer.toB58String())
      done()
    })
  })
github libp2p / js-libp2p-keychain / test / peerid.js View on Github external
it('encoded public key with DER', async () => {
    const jwk = rsaUtils.pkixToJwk(publicKeyDer)
    const rsa = new rsaClass.RsaPublicKey(jwk)
    const keyId = await promisify(rsa.hash, {
      context: rsa
    })()
    const kids = multihash.toB58String(keyId)
    expect(kids).to.equal(peer.toB58String())
  })
github libp2p / js-libp2p-keychain / test / peerid.js View on Github external
it('encoded public key with JWT', async () => {
    const jwk = {
      kty: 'RSA',
      n: 'tkiqPxzBWXgZpdQBd14o868a30F3Sc43jwWQG3caikdTHOo7kR14o-h12D45QJNNQYRdUty5eC8ItHAB4YIH-Oe7DIOeVFsnhinlL9LnILwqQcJUeXENNtItDIM4z1ji1qta7b0mzXAItmRFZ-vkNhHB6N8FL1kbS3is_g2UmX8NjxAwvgxjyT5e3_IO85eemMpppsx_ZYmSza84P6onaJFL-btaXRq3KS7jzXkzg5NHKigfjlG7io_RkoWBAghI2smyQ5fdu-qGpS_YIQbUnhL9tJLoGrU72MufdMBZSZJL8pfpz8SB9BBGDCivV0VpbvV2J6En26IsHL_DN0pbIw',
      e: 'AQAB',
      alg: 'RS256',
      kid: '2011-04-29'
    }
    const rsa = new rsaClass.RsaPublicKey(jwk)
    const keyId = await promisify(rsa.hash, {
      context: rsa
    })()
    const kids = multihash.toB58String(keyId)
    expect(kids).to.equal(peer.toB58String())
  })
github richardschneider / ipfs-encryption / src / util.js View on Github external
exports.keyId = (privateKey, callback) => {
  try {
    const publicKey = pki.setRsaPublicKey(privateKey.n, privateKey.e)
    const spki = pki.publicKeyToSubjectPublicKeyInfo(publicKey)
    const der = new Buffer(forge.asn1.toDer(spki).getBytes(), 'binary')
    const jwk = rsaUtils.pkixToJwk(der)
    const rsa = new rsaClass.RsaPublicKey(jwk)
    rsa.hash((err, kid) => {
      if (err) return callback(err)

      const kids = multihash.toB58String(kid)
      return callback(null, kids)
    })
  } catch (err) {
    callback(err)
  }
}