Creates a simple PFX (PKCS-12) file from X.509 certificate and (optional) encrypted private key file.
VB6/VBA
Debug.Print "Testing PFX_MakeFile ..." Dim strOutputFile As String Dim strCertFile As String Dim strKeyFile As String Dim strPassword As String Dim nRet As Long strOutputFile = "Bob.pfx" strCertFile = "Bob.cer" strKeyFile = "BobPrivRSAEncrypt.epk" strPassword = "password" ' Given Bob's certificate and encrypted private key file (with password "password"), ' create a PKCS-12 (pfx/p12) file. nRet = PFX_MakeFile(strOutputFile, strCertFile, strKeyFile, strPassword, "Bob's ID", 0) Debug.Print "PFX_MakeFile returns " & nRet ' Now verify that the signature is OK nRet = PFX_VerifySig(strOutputFile, strPassword, 0) Debug.Print "PFX_VerifySig returns " & nRet ' Clean up Call WIPE_String(strPassword, Len(strPassword))
Output
Testing PFX_MakeFile ... PFX_MakeFile returns 0 PFX_VerifySig returns 0
VB.NET
Console.WriteLine("Testing PFX_MakeFile ...")
Dim strOutputFile As String
Dim strCertFile As String
Dim strKeyFile As String
Dim sbPassword As StringBuilder
Dim nRet As Integer
Dim isOK As Boolean
strOutputFile = "Bob.pfx"
strCertFile = "Bob.cer"
strKeyFile = "BobPrivRSAEncrypt.epk"
sbPassword = New StringBuilder("password")
' Given Bob's certificate and encrypted private key file (with password "password"),
' create a PKCS-12 (pfx/p12) file.
nRet = Pfx.MakeFile(strOutputFile, strCertFile, strKeyFile, sbPassword.ToString(), "Bob's ID", False)
Console.WriteLine("Pfx.MakeFile returns " & nRet)
' Now verify that the signature is OK
isOK = Pfx.SignatureIsValid(strOutputFile, sbPassword.ToString())
Console.WriteLine("Pfx.SignatureIsValid returns " & isOK)
' Clean up
Call Wipe.String(sbPassword)
[Contents]