Skip to content

[Bug]: X509Certificate2.GetCertificatePublicKey returns public key parameters (modulus and exponent) instead of the key value, and there is no way to obtain the generated public key value from an X509 certificate #4238

@adrogin

Description

@adrogin

Describe the issue

Internally, X509Certificate2.GetCertificatePublicKey invokes AsymmetricAlgorithm.ToXmlString(false) which returns an XML representation of the crypto service provider. In case of the RSA provider, this is an XML containing the modulus and the exponent values:

<RSAKeyValue>
   <Modulus>…</Modulus>
   <Exponent>…</Exponent>
</RSAKeyValue>

RSA.ToXmlString(Boolean) Method

I can use the returned XML to initialize a signature key instance, but can't obtain the public key value that can be sent to a third party to verify a signature. Neither does the SignatureKey codeunit have any methods to extract the public key.

Expected behavior

Codeunit X509Certificate2 should have a method similar to CertificateManagement.GetPublicKeyAsBase64String which is a wrapper around .Net X509Certificate2.GetRawCertData().

Steps to reproduce

For now, the only way to obtain the public key from a certificate is to upload it into the isolated storage and use the "Certificate Management" codeunit, but no method to get the key when the certificate comes from an external source.

Additional context

No response

I will provide a fix for a bug

  • I will provide a fix for a bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions