Saves an internal EC key string to an unencrypted key file.
Public Declare Function ECC_SaveKey Lib "diCrPKI.dll" (ByVal strFileOut As String, ByVal strIntKeyString As String, ByVal nOptions As Long) As Long
nRet = ECC_SaveKey(strFileOut, strIntKeyString, nOptions)
long __stdcall ECC_SaveKey(const char *szFileOut, const char *szIntKeyString, long nOptions);
If successful, the return value is zero; otherwise it returns a nonzero error code.
Public Function eccSaveKey
(szOutputFile As String, szKeyStr As String, Optional nOptions As Long = 0) As Long
static int dipki::Ecc::SaveKey (std::string outputFile, std::string internalKey, KeyType keyType=KeyType::Default, Format fileFormat=Format::Binary)
static Ecc.save_key(outputfile, intkeystr, keytype=0, fileformat=0)
EC public keys are always saved in SubjectPublicKeyInfo
format [RFC5480].
By default, NIST/SEC curve private keys are saved in ECPrivateKey
format [RFC5915].
Use the PKI_KEY_TYPE_PKCS8 option to save in PKCS#8 PrivateKeyInfo
format [RFC5208].
[New in v22.0] Safe curve private keys (X25519, Ed25519, X448 and Ed448) are always saved in PKCS#8 v2 OneAsymmetricKey
format including the public key [RFC5958].
Add the option PKI_KEY_LEGACY to save in older PKCS#8 v1 PrivateKeyInfo
format [RFC5208]
excluding the public key.
To save a private key in encrypted form, use ECC_SaveEncKey.
Dim nRet As Long Dim nChars As Long Dim strIntKey As String Dim strKeyFile As String Dim strPassword As String Dim strNewKeyFile As String Dim strTypeName As String Dim strFileName As String strKeyFile = "myeckeyp256.p8" strPassword = "password" Debug.Print "FILE: " & strKeyFile ' Find required length of internal key string nChars = ECC_ReadPrivateKey("", 0, strKeyFile, 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), strKeyFile, strPassword, 0) ' Caution: internal key string is only valid for the current session Debug.Print "[" & strIntKey & "]" ' Now save in a different format: ECPrivatekey in PEM encoding strNewKeyFile = "myeckey.pem" nRet = ECC_SaveKey(strNewKeyFile, strIntKey, PKI_KEY_FORMAT_PEM) Debug.Print "ECC_SaveKey returns " & nRet & " (expected 0)" ' Check the type 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)
FILE: myeckeyp256.p8 ECC_ReadPrivateKey returns 100 (expected +ve) [PVECF7UtCxnQIin+PBxnvYk8GsAsMbPfKYUnfZv/EU/oSeJtW1UAt1QMZT60Solrg6PtKLHsGlWT8IxgKTfzIf3+NK/Ulq0+z6Id] ECC_SaveKey returns 0 (expected 0) myeckey.pem: EC PRIVATE KEY
ECC_ReadPrivateKey ECC_ReadPublicKey ECC_SaveEncKey ECC_PublicKeyFromPrivate