Reads an EC public key from a file into an internal key string.
Public Declare Function ECC_ReadPublicKey Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strKeyFileOrString As String, ByVal nOptions As Long) As Long
nRet = ECC_ReadPublicKey(strOutput, Len(strOutput), strKeyFileOrString, nOptions)
long __stdcall ECC_ReadPublicKey(char *szOutput, long nOutChars, const char *szKeyFileOrString, long nOptions);
If successful, the return value is the number of characters in or required for the output string; otherwise it returns a negative error code.
Public Function eccReadPublicKey
(szKeyFileOrString As String, Optional nOptions As Long = 0) As String
static std::string dipki::Ecc::ReadPublicKey (std::string keyFileOrString)
static Ecc.read_public_key(keyfileorstr)
For the "raw" VBA/C function, the user must allocate an output string buffer szOutput of the required length. Specify a zero nOutChars or an empty string for szOutput to find the required length. ANSI C users must add one to this value when allocating memory.
[New in v12.0] An EC public key can also be read directly from an X.509 certificate (or its base64 representation).
Dim nRet As Long Dim nChars As Long Dim strIntKey As String Dim strKeyFile As String Dim strQuery As String strKeyFile = "myeckeyp521.pub" Debug.Print "FILE: " & strKeyFile ' Find required length of internal key string nChars = ECC_ReadPublicKey("", 0, strKeyFile, 0) Debug.Print "ECC_ReadPublicKey returns " & nChars & " (expected +ve)" ' Dimension the string to receive output strIntKey = String(nChars, " ") ' Read into internal key string nChars = ECC_ReadPublicKey(strIntKey, Len(strIntKey), strKeyFile, 0) Debug.Print "[" & strIntKey & "]" ' Find the key size in bits (NB returned directly) strQuery = "keyBits" nRet = ECC_QueryKey("", 0, strIntKey, strQuery, 0) Debug.Print "ECC_QueryKey('" & strQuery & "')=" & nRet & " (expected +ve)" ' Is it a private or public key? strQuery = "isPrivate" nRet = ECC_QueryKey("", 0, strIntKey, strQuery, 0) Debug.Print "ECC_QueryKey('" & strQuery & "')=" & nRet & " (expected 0)"
FILE: myeckeyp521.pub ECC_ReadPublicKey returns 212 (expected +ve) [MIGbMBAGByqGSM49AgEGBSuB ... NARus1tKwwWhEJGs=] ECC_QueryKey('keyBits')=521 (expected +ve) ECC_QueryKey('isPrivate')=0 (expected 0)
Dim strIntKey As String ' Read in public key from file strIntKey = eccReadPublicKey("myeckeyp256.pub") Debug.Assert Len(strIntKey) > 0 Debug.Print "Key curve=" & eccQueryKey(strIntKey, "curveName", 0) & " keyBits=" & _ eccQueryKey(strIntKey, "keyBits", 0) & _ " and is a " & _ IIf(eccQueryKey(strIntKey, "isPrivate") = "1", "Private", "Public") & " key" Debug.Print eccQueryKey(strIntKey, "publicKey") Debug.Print "KeyHashCode=0x" & Hex(ECC_KeyHashCode(strIntKey)) ' Read in private key from file strIntKey = eccReadPrivateKey("myeckeyp256.p8", "password") Debug.Assert Len(strIntKey) > 0 Debug.Print "Key curve=" & eccQueryKey(strIntKey, "curveName", 0) & " keyBits=" & _ eccQueryKey(strIntKey, "keyBits", 0) & _ " and is a " & _ IIf(eccQueryKey(strIntKey, "isPrivate") = "1", "Private", "Public") & " key" Debug.Print eccQueryKey(strIntKey, "publicKey") Debug.Print "KeyHashCode=0x" & Hex(ECC_KeyHashCode(strIntKey)) ' Derive public key from private key strIntKey = eccPublicKeyFromPrivate(strIntKey) Debug.Assert Len(strIntKey) > 0 Debug.Print "Key curve=" & eccQueryKey(strIntKey, "curveName", 0) & " keyBits=" & _ eccQueryKey(strIntKey, "keyBits", 0) & _ " and is a " & _ IIf(eccQueryKey(strIntKey, "isPrivate") = "1", "Private", "Public") & " key" Debug.Print eccQueryKey(strIntKey, "publicKey") Debug.Print "KeyHashCode=0x" & Hex(ECC_KeyHashCode(strIntKey))
ECC_ReadPrivateKey ECC_QueryKey