Skip to content

Instantly share code, notes, and snippets.

@mururu
Created June 25, 2015 04:45
Show Gist options
  • Save mururu/c3e2c067f57976da8afe to your computer and use it in GitHub Desktop.
Save mururu/c3e2c067f57976da8afe to your computer and use it in GitHub Desktop.
extract_public_key.erl
-include_lib("public_key/include/public_key.hrl").
extract_public_key(CertPath)
{ok, CertBinary} = file:read_file(CertPath),
CertPemEntries = public_key:pem_decode(CertBinary),
{'Certificate', Cert, _} = lists:keyfind('Certificate', 1, CertPemEntries),
#'OTPCertificate'{
tbsCertificate = #'OTPTBSCertificate'{
subjectPublicKeyInfo = #'OTPSubjectPublicKeyInfo'{
subjectPublicKey = PublicKey
}
}
} = public_key:pkix_decode_cert(Cert, otp)
PublicKey.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment