Translate Java to Python -- signing strings with PEM certificate files
Posted
by erikcw
on Stack Overflow
See other posts from Stack Overflow
or by erikcw
Published on 2010-04-15T02:53:11Z
Indexed on
2010/04/15
3:03 UTC
Read the original article
Hit count: 573
I'm trying to translate the follow Java into its Python equivalent.
// certificate is contents of https://fps.sandbox.amazonaws.com/certs/090909/PKICert.pem
// signature is a string that I need to verify.
CertificateFactory factory = CertificateFactory.getInstance("X.509");
X509Certificate x509Certificate =
(X509Certificate) factory.generateCertificate(new ByteArrayInputStream(certificate.getBytes()));
Signature signatureInstance = Signature.getInstance(signatureAlgorithm);
signatureInstance.initVerify(x509Certificate.getPublicKey());
signatureInstance.update(stringToSign.getBytes(UTF_8_Encoding));
return signatureInstance.verify(Base64.decodeBase64(signature.getBytes()));
This is for the PKI signature verification used by AWS FPS. http://docs.amazonwebservices.com/AmazonFPS/latest/FPSAccountManagementGuide/VerifyingSignature.html
Thanks for your help!
© Stack Overflow or respective owner