开发者

Getting public key from digital signature

开发者 https://www.devze.com 2023-03-13 02:38 出处:网络
I am working on a java based licensing project. I have a digita开发者_JAVA百科l certificate file and the datafor which the signature was generated. Is there some API or means to get the public key fro

I am working on a java based licensing project. I have a digita开发者_JAVA百科l certificate file and the data for which the signature was generated. Is there some API or means to get the public key from these information? Basically Public Key from the data and digital certificate information.


If you digital signature is of format PKCS#7 - not detached, then there is a possibility that the sender would have included the certificate as a part of the digital signature.

You will be required to parse the signature to get the certificate.


The Bouncy Castle API has a SignedData class which has a method for getting certificate(s).


Your question is very vague IMHO.

I have a digital certificate file and the data for which the signature was generated

If the certificate file has the public key used to verify the signature then you can load it using standard java apis (assuming X509 Certificates).

FileInputStream fin = new FileInputStream("PathToCertificate");
CertificateFactory f = CertificateFactory.getInstance("X.509");
X509Certificate certificate = (X509Certificate)f.generateCertificate(fin);
PublicKey pk = certificate.getPublicKey();

Once you have the public key you can use it to verify the signature.
Is this what you want?


The certificate must bear a reference to the id of the key used to certify your data. From this key, should be able to contact the corresponding certificate authority and obtain the public key by providing its id. It may be available from a public repository too.

The id of the certificate authority should also appear on this certificate.

There are APIs available for sure, but the question is, which framework are you using for digital signatures? Do you have its name? Do you know the certificate type?

0

精彩评论

暂无评论...
验证码 换一张
取 消