Created
January 15, 2024 19:44
-
-
Save FauxFaux/0c14779d76c6e966532357124731a0a9 to your computer and use it in GitHub Desktop.
node-forge-fromDer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const forge = require("node-forge"); | |
const badKeyValue = `MGsCAQEEIDrDtTbDnMKRwpvDpzkxLQpwO8O8w6zDq8OWwo | |
HCtcKedjrDgsOCMMOiw4rDqBsewpDCucKhRANCAAQ/c3zDq8K4wpnDvcO6N3nChsOUfnHD | |
k8OcQsORwqHCtMKFwrvCq08mw77CnsOHAl7DliQAwrsJX8OWYWzCn2lVw5DCg8OIeGfDpM | |
KxK8O4wr3Cn8OFdsO1HVhbw4xGWmbCpw==`; | |
const goodKeyValue = `MGsCAQEEIEjDv8KoIcO5wrrChl3DsUDDvXjDpMOYwrHDjMKKw | |
55pMT7CrMK8O8KQIsOTasK5SUZ7wqFEA0IABAQxUMOWennChGpcwoTDhsOvUzgeFsK3w7bCscK1wo | |
MDwrEuX8OPwrTCn8KUKcOiYcOtw6JRw7LDrSPCvMOtw4t/w4PDlcOQw5zDqiTCjDbCocKowpXCjMK | |
Uw41Vw49jE8Ogw7rDvEg=`; | |
const unBase64 = (s) => Buffer.from(s, "base64").toString(); | |
const toHex = (s) => Buffer.from(s).toString("hex").slice(0, 15) + '...'; | |
for (const [name, value] of [["bad", badKeyValue], ["good", goodKeyValue]]) { | |
for (const decodeBitStrings of [true, false]) { | |
const bytes = unBase64(value); | |
const msg = forge.asn1.fromDer(bytes, { decodeBitStrings }); | |
const pvv = msg.value[2].value[0].value; | |
console.log(name, "key, decode bit strings:", decodeBitStrings, "point value:", | |
typeof pvv === "string" ? toHex(pvv) : `[{value: '${toHex(pvv[0].value)}'}]`, | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bad key, decode bit strings: true point value: [{value: '737cc3abc2b8c29...'}] | |
bad key, decode bit strings: false point value: 00043f737cc3abc... | |
good key, decode bit strings: true point value: 0004043150c3967... | |
good key, decode bit strings: false point value: 0004043150c3967... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment