CryptoSys PKI Pro Manual

ECC_SaveEncKey

Saves an internal EC private key string to an encrypted private key file.

VBA/VB6 Syntax

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)

C/C++ Syntax

long __stdcall ECC_SaveEncKey(const char *szFileOut, const char *szIntKeyString, const char *szPassword, const char *szParams, long nOptions);

Parameters

szFileOut
[in] name of key file to be created.
szIntKeyString
[in] the private key in an internal key string.
szPassword
[in] the password to be used for the encrypted key file
szParams
[in] (optional) parameters. Set as the empty string "" for defaults. Otherwise include a set of attribute-value pairs separated by a semi-colon ";" to set options from the following
nOptions
[in] containing a flag to indicate the algorithm to be used to encrypt the private key file. Select from:
PKI_PBE_SHA_3DES (0) for "pbeWithSHAAnd3-KeyTripleDES-CBC" (default)
PKI_PBE_PBKDF2_DESEDE3 for PBKDF2 using des-EDE3-CBC
PKI_PBE_PBKDF2_AES128 for PBKDF2 using aes128-CBC
PKI_PBE_PBKDF2_AES192 for PBKDF2 using aes192-CBC
PKI_PBE_PBKDF2_AES256 for PBKDF2 using aes256-CBC
(there are more options - see security options for encrypted private keys)
and optionally add
PKI_KEY_FORMAT_PEM to save the key files in PEM form (default is binary DER-encoded format).

Returns (VBA/C)

If successful, the return value is zero; otherwise it returns a nonzero error code.

VBA Wrapper Syntax

Public Function eccSaveEncKey (szOutputFile As String, szKeyStr As String, szPassword As String, Optional szParams As String = "", Optional nOptions As Long = 0) As Long

.NET Equivalent

Ecc.SaveEncKey Method

C++ (STL) Equivalent

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)

Python Equivalent

static Ecc.save_enc_key(outputfile, intkeystr, password, pbescheme=0, params='', fileformat=0)

Remarks

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:

These are case-insensitive and work only with the PKI_PBE_PBKDF2_ options. This will override any PKI_HMAC_ flag in nOptions

Set szParams as the empty string "" for defaults.

Example

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

See Also

ECC_ReadPrivateKey ECC_SaveKey

[Contents] [Index]

[PREV: ECC_ReadPublicKey...]   [Contents]   [Index]   
   [NEXT: ECC_SaveKey...]

Copyright © 2004-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-09-23T07:52:09Z.