How to get Hash Certificate as Base 64 String in MS BC SaaS

AlexLimAlexLim Member Posts: 16
Hi,

I tried to get the hash certificate, but I keep failing to get what I want. Below is the Powershell command and what I have understood so far.

//Powershell command
$certPath = Read-Host -Prompt "Enter the path of your certificate file (*.pfx/*.p12)"
$password = Read-Host -AsSecureString -Prompt "Enter the password for your certificate file"
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($certPath, $password)
# Compute the hash of the certificate using SHA-256
$sha256 = [System.Security.Cryptography.SHA256]::Create()
$certHash = $sha256.ComputeHash($cert.RawData)
# Convert the hash to a Base64 encoded string
$CertDigest = [Convert]::ToBase64String($certHash)
Write-Output "Retrieve CertDigest: $CertDigest "

//AL
1. Codeunit X509Certificate2
This is 1 of essential codeunit I need to use, however it doesn't have any way to convert the certificate same result as the powershell

2. Codeunit "Certificate Management"
Function GetRawCertDataAsBase64String able to convert the Certificate Raw Data to Base 64 String. I believe this is the closest result I can get, however I still not get the result I need as I need to hash the certificate raw data and then only convert to base 64 string.

I also tried some solution that not make any sense, like convert the GetRawCertDataAsBase64String to another form with Base64Convert.FromBase64 (Codeunit "Base64 Convert")

3. Record "Isolated Certificate"
Where the table to store the certificate I needed, but nothing much can do within it self

4. Codeunit "Cryptography Management"
Function GenerateHashAsBase64String, this is the function I will need to use a-lot. However, it's will always give different result as it only accept string, but not certificate raw data in Byte Array (I also tried some crazy idea, but all required DotNet and way too complex to continue, at least to me)

My current conclusion, in order to achieve same result as the powershell, I need to write a solution outside AL, such as .Net(?). However, I still not very convince as the most of the component I need is able to handle within AL, but left this small but very important part.

Any guidance or information is much appreciate.

Note: I wish my conclusion is not correct, as I never write a solution outside AL. :'(
Sign In or Register to comment.