mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-04-24 20:22:29 +00:00
* fix: replace node buffers with uint8arrays All usage of node buffers have been replaced with uint8arrays. BREAKING CHANGES: - Where node Buffers were returned, now Uint8Arrays are * chore: remove commented code
23 lines
721 B
JavaScript
23 lines
721 B
JavaScript
'use strict'
|
|
|
|
const multibase = require('multibase')
|
|
const ciphers = require('../ciphers/aes-gcm')
|
|
|
|
module.exports = {
|
|
/**
|
|
* Attempts to decrypt a base64 encoded PrivateKey string
|
|
* with the given password. The privateKey must have been exported
|
|
* using the same password and underlying cipher (aes-gcm)
|
|
*
|
|
* @param {string} privateKey A base64 encoded encrypted key
|
|
* @param {string} password
|
|
* @returns {Promise<Uint8Array>} The private key protobuf
|
|
*/
|
|
import: async function (privateKey, password) {
|
|
const base64 = multibase.names.base64
|
|
const encryptedKey = base64.decode(privateKey)
|
|
const cipher = ciphers.create()
|
|
return await cipher.decrypt(encryptedKey, password)
|
|
}
|
|
}
|