VBScript
VBScript
Load Identities from PEM Text
See more PFX/P12 Examples
Demonstrates Pfx.LoadPem, which loads one or more certificate/private-key identities from PEM-formatted text and builds the contents of the Pfx object.
The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.
Background. The password decrypts any encrypted private keys in the PEM. This builds a PFX in memory from PEM material, which can then be serialized to PKCS#12.
Chilkat VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
set pfx = CreateObject("Chilkat.Pfx")
' The file path is relative to the application's current working directory. An absolute path
' may also be used. Supply the path appropriate to your own environment.
' Load the PEM text (certificates and private keys) into a string.
set sbPem = CreateObject("Chilkat.StringBuilder")
bLoaded = sbPem.LoadFile("qa_data/identity.pem")
If (bLoaded <> 1) Then
outFile.WriteLine("Failed to load the PEM file.")
WScript.Quit
End If
pemText = sbPem.GetAsString()
If (sbPem.LastMethodSuccess = 0) Then
outFile.WriteLine(sbPem.LastErrorText)
WScript.Quit
End If
' The password decrypts any encrypted private keys in the PEM (use an empty string if none are
' encrypted). A password should come from a secure source rather than being hard-coded.
password = "myPemPassword"
success = pfx.LoadPem(pemText,password)
If (success = 0) Then
outFile.WriteLine(pfx.LastErrorText)
WScript.Quit
End If
outFile.WriteLine("Loaded " & pfx.NumPrivateKeys & " private key(s).")
outFile.Close