mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-06-23 01:41:50 +00:00
feat: key exchange with jsrsasign (#115)
* feat: export/import password protected RSA key * docs: crypto.key.import * test: import with wrong password * fix: lint * test: importing openssl keys * just to trigger circle with new ubuntu * feat: get the RSA key id * feat: get the ED 25519 key id * feat: pbkdf2 * fix(pbkdf2): base64 has more chars to guess than hex * chore: update deps
This commit is contained in:
committed by
David Dias
parent
f3cb8ced36
commit
b3421284f9
@ -2,6 +2,8 @@
|
||||
|
||||
const protobuf = require('protons')
|
||||
const keysPBM = protobuf(require('./keys.proto'))
|
||||
const jsrsasign = require('jsrsasign')
|
||||
const KEYUTIL = jsrsasign.KEYUTIL
|
||||
|
||||
exports = module.exports
|
||||
|
||||
@ -115,3 +117,17 @@ exports.marshalPrivateKey = (key, type) => {
|
||||
|
||||
return key.bytes
|
||||
}
|
||||
|
||||
exports.import = (pem, password, callback) => {
|
||||
try {
|
||||
const key = KEYUTIL.getKey(pem, password)
|
||||
if (key instanceof jsrsasign.RSAKey) {
|
||||
const jwk = KEYUTIL.getJWKFromKey(key)
|
||||
return supportedKeys.rsa.fromJwk(jwk, callback)
|
||||
} else {
|
||||
throw new Error(`Unknown key type '${key.prototype.toString()}'`)
|
||||
}
|
||||
} catch (err) {
|
||||
callback(err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user