(Unicode C++) Convert PKCS12 / PFX to Java KeyStore
Converts a PKCS12 / PFX file to a Java keystore (JKS) file.
#include <CkJavaKeyStoreW.h>
#include <CkPfxW.h>
void ChilkatSample(void)
{
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkJavaKeyStoreW jks;
CkPfxW pfx;
const wchar_t *pfxPassword = L"secret";
// Load a PKCS12 from a file.
bool success = pfx.LoadPfxFile(L"/someDir/my.p12",pfxPassword);
if (success != true) {
wprintf(L"%s\n",pfx.lastErrorText());
return;
}
const wchar_t *alias = L"someAlias";
const wchar_t *jksPassword = L"jksSecret";
// Add the PKCS12 to the empty Java keystore object:
success = jks.AddPfx(pfx,alias,jksPassword);
if (success != true) {
wprintf(L"%s\n",jks.lastErrorText());
return;
}
// Write the Java keystore to a file:
success = jks.ToFile(jksPassword,L"/jksFiles/my.jks");
if (success != true) {
wprintf(L"%s\n",jks.lastErrorText());
}
else {
wprintf(L"Successfully converted PKCS12 to JKS\n");
}
}
|