[Network] Example of setting Data property from X509Certificate2
See original GitHub issueIt wasn’t clear to me how to set the certificate Data property given an X509Certificate2. I spent several hours trying to figure this out ultimately cloning the repository to look at the code and examples/unit tests. This is how it’s done:
X509Certificate2 certificate;
...
string base64EncodedCertificate = Convert.ToBase64String(certificate.Export(X509ContentType.Cert));
new ApplicationGatewayTrustedClientCertificate
{
Data = BinaryData.FromObjectAsJson(base64EncodedCertificate);
}
Nothing else I tried would work. IMO, this is not the most obvious usage. Other things I tried that don’t work but seem more sensible:
new ApplicationGatewayTrustedClientCertificate
{
Data = BinaryData.FromBytes(certificate.Export(X509ContentType.Cert));
}
new ApplicationGatewayTrustedClientCertificate
{
Data = BinaryData.FromString(Convert.ToBase64String(certificate.Export(X509ContentType.Cert)));
}
The documentation on how to set the BinaryData property isn’t very helpful unless you already know the answer. For setting certificate Data would be much more helpful to show an example based on an X509Certificate rather than a string “foo”.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 3f018383-f655-4feb-d90f-7cb4fa69c002
- Version Independent ID: 31b01ae5-a236-88cd-23ec-6eee97ec8762
- Content: ApplicationGatewayAuthenticationCertificate Class (Azure.ResourceManager.Network.Models) - Azure for .NET Developers
- Content Source: xml/Azure.ResourceManager.Network.Models/ApplicationGatewayAuthenticationCertificate.xml
- Service: azure
- GitHub Login: @rloutlaw
- Microsoft Alias: routlaw
Issue Analytics
- State:
- Created 6 months ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
X509Certificate2 Class (System.Security.Cryptography. ...
The following example creates a command-line executable that takes a certificate file as an argument and prints various certificate properties to the console....
Read more >X509Certificate2.RawData Property (System.Security. ...
The following code example creates a command-line executable that takes a certificate file as an argument and prints various certificate properties to the ......
Read more >Associate a private key with the X509Certificate2 class in .net
net. I'm working on some code that creates a X509certificate and a public/private key pair. The public key is added to the certificate...
Read more >Seven tips for working with X.509 certificates in .NET
Tip 1: Understand the difference between certificates and PKCS #12/PFX files. In .NET, the X509Certificate2 object has properties for the ...
Read more >Accessing and using certificate private keys in .NET ...
An X509Certificate2 class has a PrivateKey property of AsymmetricAlgorithm type. AsymmetricAlgorithm class is abstract class for any asymmetric ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@CodyBatt The reason why we expect the input of
BinaryData
asjson
is based on how we serialize it, we thoughtData
could be anything as configured in autorest.mdBut the type of
Data
is defined asstring
in Swagger. This is the similar to https://github.com/Azure/azure-sdk-for-net/issues/33804, we are looking into a proper fix for it.cc @m-nash
Okay