How to convert an exported key to base64 in nodejs? #7715
Labels
kind/bug
A bug in existing code (including security flaws)
need/triage
Needs initial labeling and prioritization
markg85 commentedOct 5, 2020
Hi,
I'm using IPFS 0.7.0 with the shiny new feature to export keys.
So i do:
Which gives me a "test.key" in binary libp2p protobuf format.
What i try to do now is get that key working in nodejs crypto.
This is where i'm hitting some snags.
In node.js i need to import the key as a PEM key to be able to import and use it. This means it needs to be in this exact format:
Begin and end are easy :)
The key needs to be in base64.
Now to load this into javascript i did the following:
Note that very last console.log line. There i'm printing the key, which results in:
That's too long.
The
keyBufferobject is (i verified that) 64 bytes long. So it does seem to match what the libp2p spec tells.The base64 result is however 88 characters which doesn't seem to be right. Importing it as that gives me an error of:
header too long.I'm sure i'm missing a conversion somewhere. But where and from what to what is not clear to me.
Thank a lot!
Cheers,
Mark
The text was updated successfully, but these errors were encountered: