Saves an internal EC private key string to an encrypted private key file.
Public Declare Function ECC_SaveEncKey Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strIntKeyString As String, ByVal strPassword As String, ByVal strParams As String, ByVal nOptions As Long) As Long
nRet = ECC_SaveEncKey(strFileOut, strIntKeyString, strPassword, strParams, nOptions)
long __stdcall ECC_SaveEncKey(const char *szFileOut, const char *szIntKeyString, const char *szPassword, const char *szParams, long nOptions);
""
for defaults.
Otherwise include a set of attribute-value pairs separated by a semi-colon ";" to set options from the following
count=<nnn>
to set the iteration count used in the PBKDF method,
e.g. "count=5000;"
[default=2048
]
prf=<hmac-name>
to change the HMAC algorithm used in the PBKDF2 method,
e.g. "prf=hmacWithSHA256;"
[default=hmacwithSHA1
]
"pbeWithSHAAnd3-KeyTripleDES-CBC"
(default)des-EDE3-CBC
aes128-CBC
aes192-CBC
aes256-CBC
If successful, the return value is zero; otherwise it returns a nonzero error code.
Public Function eccSaveEncKey
(szOutputFile As String, szKeyStr As String, szPassword As String, Optional szParams As String = "", Optional nOptions As Long = 0) As Long
static int dipki::Ecc::SaveEncKey (std::string outputFile, std::string internalKey, std::string password, PbeScheme pbes=PbeScheme::Default, std::string paramString="", Format fileFormat=Format::Binary)
static Ecc.save_enc_key(outputfile, intkeystr, password, pbescheme=0, params='', fileformat=0)
Use this function to save a private key in a new encrypted file format, perhaps with stronger encryption. Use the PKI_KEY_FORMAT_PEM flag to save in PEM-encoded format. You must first read in the old private key file into an "internal" private key string which is only valid for the current session.
Valid values for the "prf" parameter in szParams are:
hmacWithSHA1
(default)hmacWithSHA224
hmacWithSHA256
hmacWithSHA384
hmacWithSHA512
Set szParams as the empty string ""
for defaults.
Dim nRet As Long Dim nChars As Long Dim strIntKey As String Dim strPriKeyFile As String Dim strPassword As String Dim strNewKeyFile As String Dim strTypeName As String Dim strFileName As String strPriKeyFile = "myeckeyp256.p8" strPassword = "password" ' Find required length of internal key string nChars = ECC_ReadPrivateKey("", 0, strPriKeyFile, strPassword, 0) Debug.Print "ECC_ReadPrivateKey returns " & nChars & " (expected +ve)" ' Dimension the string to receive output strIntKey = String(nChars, " ") ' Read it in nChars = ECC_ReadPrivateKey(strIntKey, Len(strIntKey), strPriKeyFile, strPassword, 0) Debug.Print "[" & strIntKey & "]" ' Now save in a different format: ECPrivatekey strNewKeyFile = "myeckey.key" nRet = ECC_SaveKey(strNewKeyFile, strIntKey, 0) Debug.Print "ECC_SaveKey returns " & nRet & " (expected 0)" ' Check the types of file we made strTypeName = String(PKI_ASN1_TYPE_MAXCHARS, " ") strFileName = strNewKeyFile nChars = ASN1_Type(strTypeName, Len(strTypeName), strFileName, 0) If nChars > 0 Then Debug.Print strFileName & ": " & Left(strTypeName, nChars)
ECC_ReadPrivateKey returns 100 (expected +ve) [PVECvfqrR9ge+DBQVJtnBBrw6gH+qmnZSX7apDuXoWcwmvIWLXNbXHG3Bo1cAXGuLUzIeWyb4M5G2aUnn/3Y/9d1/KjQjTnNXeky] ECC_SaveKey returns 0 (expected 0) myeckey.key: EC PRIVATE KEY
ECC_ReadPrivateKey ECC_SaveKey