Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X509Certificate fingerprint #79

Open
StebeletskyiMyroslav opened this issue Jun 12, 2024 · 3 comments
Open

X509Certificate fingerprint #79

StebeletskyiMyroslav opened this issue Jun 12, 2024 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@StebeletskyiMyroslav
Copy link

Hiow can i get formatted fingerprint of certificate ?

Foe example i have following certificate:

-----BEGIN CERTIFICATE-----
MIICxDCCAaygAwIBAgIIBKsgcOucPtIwDQYJKoZIhvcNAQELBQAwIjEgMB4GA1UE
AxMXUG9ydG5veCBTU08gQ2VydGlmaWNhdGUwHhcNMjQwNjExMTY1MjIzWhcNMjcw
NjExMTY1MjIzWjAiMSAwHgYDVQQDExdQb3J0bm94IFNTTyBDZXJ0aWZpY2F0ZTCC
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMNqit0JSoscHlrO+ggUpww1
bmv1XF7Qz2y/VFxPNSKE9WMAYbdYlV9m5ZF0dpPdozvbDYYr60H6s0FJYt42951r
NGFKI+EwQs7kTv+LgIvXPTvI0CKnO+ULzDtjeE618ouKKLmULJBilr5THnngrjdd
jTLd1jYUlVa2w9C7A1RZeBwJVxG8jTbfVzZReVir7Iu0k1nxxjiOuvSj1oqfH+NT
mLthwXBuYpSH0wteU2TcXyJYOCkmYklWVB5d4z0W6t8G8i+GmIpnoA9db7NYDmbj
iMyxgv0DSWLWHdtbDyDgP/8n9X5uTxdvcADK1iE1vAlK1dbibf9Pw2bt7yLKUZcC
AwEAATANBgkqhkiG9w0BAQsFAAOCAQEAocTLQoE+ERTNES36lykJXq05ryiBMDda
xlEvSsOzbRWxRPPZgBHlMYlv+CKQGyM3nv2VClGVMbx5TdVB7NkrxbmFJoNxjjyk
HkZa0lvyYxDgJVsCj2l9az1jFCU9KGJ++LAeCVwgrTBgFODAUYBA3ErdDgYKI2P9
C4HHf2ytQpBX1201NCHULZG+bduJIiKW2ourCfulppbM1M4AwSbsDw+efyKd9Gn7
4wJiQFiYXsgKkWnb39Cs9WKJi6DGyJV2/cQ9pR8y3KBz4WIddRmj6VAUBrvKvOR5
vpM5dy8b/U5Bsb4SO5S0Idx69+/tko/WUgxIUyhIXPHFh4+AE3+uaA==
-----END CERTIFICATE-----

I try to use some online services that detect certificate fingerprint, and what i have with mentioned above certificate:
sha-1: eab12636cfe4526d0c2c3a615ac73fc0689e2d8d.

I'm just asking how can i do the same with @peculiar/x509 library.

@StebeletskyiMyroslav
Copy link
Author

StebeletskyiMyroslav commented Jun 12, 2024

And yes, i know about getThumbprint method. It returns array of bytes.
But the problem occurs when i'm trying co convert this value to some hash similar value.
i'm just getting some strange symbols. It would be nice if you provide me an example how can i convert (decode) the result of getThumbprint method to hash string.

@StebeletskyiMyroslav
Copy link
Author

If someone wondering how to do it, here is solution for browser environment:

const buf2hex = (buffer: ArrayBuffer): string => {
return [...new Uint8Array(buffer)]
.map(x => x.toString(16).padStart(2, '0'))
.join('');
}

@trasherdk
Copy link

The solution from #34

const cert = new x509.X509Certificate(pem);
const thumbprint = await cert.getThumbprint();
const formattedThumbprint: string[] = [];
for (const octet of Buffer.from(thumbprint)) {
  formattedThumbprint.push(`${octet.toString(16)}`.padStart(2, "0").toUpperCase());
}
console.log(formattedThumbprint.join(":")); // 10:B9:24:B0:18:57:23:F2:2D:EB:FD:94:37:55:85:E9:CF:1D:8B:93

@microshine microshine added the help wanted Extra attention is needed label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants