0

Downloading a cert from API - JKS format

Using Powershell to download a cert in JKS format. 

##########################################

# Get API key using Connect-TPP function
$TPPConn = Connect-TPP -server $server -credential $credential -IgnoreSSLWarnings:$IgnoreSSLWarnings -Verbose

$CertDN = "\VED\Policy\Certificates\fakecert.fake.com

# PowerShell allows us to submit a hashtable body on the GET function. This keeps our URI readable!
$htBody = @{
CertificateDN = "$CertDN"
Format ="JKS"
IncludeChain = "false"
IncludePrivateKey= "false"
Password = "PASSWORD1233456"
FriendlyName = "fakecert.fake.com_2-20"
Recursive = "false"
KeystorePassword = "PASSWORD1233456"

} | ConvertTo-Json


#Execute call to TPP

$Criticalcerts = Invoke-RestMethod -Method POST -Uri "$($TPPConn.BaseURI)/Certificates/Retrieve" `
-Body $htBody -Headers $TPPConn.Headers -ContentType 'application/json'

 

#Convert from Base64

$EncodedData = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($Criticalcerts.CertificateData))

 

#OutPut to jks file
$EncodedData | Out-File "C:\Codebase\test.jks"

##############################################################

 

Keytool is giving me an "invalid format". Unsure if I needed to do this is a different way

 

2 comments

Please sign in to leave a comment.