Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

How to get PrivateKey? #132

Open
fmoric opened this issue Oct 17, 2019 · 2 comments
Open

How to get PrivateKey? #132

fmoric opened this issue Oct 17, 2019 · 2 comments

Comments

@fmoric
Copy link

fmoric commented Oct 17, 2019

How to get private key from certificate?
For example use to SignXmlText function?

I run through all codeunits and i see no way.
I wanted to make extension that has to sign an xml and send it.

So i would appreciate some help.

@SjoerddeClippelaar
Copy link

Hi Filip,

In Certificates you can upload a certificate now (with password if needed).
You can use codeunit 1259 Certificate Management to get the certificate.
Use the function VerifyCert and than use the global DotNet_X509Certificate2.

When you have the certificate you can do the following

Name DataType Subtype Length
DotNetRSA DotNet System.Security.Cryptography.RSA.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'  
DotNetRSACertificateExtensions DotNet System.Security.Cryptography.X509Certificates.RSACertificateExtensions.'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'  

DotNetRSA := DotNetRSACertificateExtensions.GetRSAPrivateKey(DotNetX509Certificate2);
CertificateXml := DotNetRSA.ToXmlString(TRUE);

CertificateXml contains the privatekey (see https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.rsa.toxmlstring?view=netframework-4.8)

@fmoric
Copy link
Author

fmoric commented Oct 17, 2019

Ok, i get that part, but that's using DotNet DataType and DotNet is only available on-premise.
I was wondering if there is any way of using only External functions, and building extension?

I would need it for local functionality, i need to send invoices to TA.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants