CryptoSys PKI Pro Manual

ECC_ReadPublicKey

Reads an EC public key from a file into an internal key string.

VBA/VB6 Syntax

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)

C/C++ Syntax

long __stdcall ECC_ReadPublicKey(char *szOutput, long nOutChars, const char *szKeyFileOrString, long nOptions);

Parameters

szOutput
[out] string of sufficient length to receive the output.
nOutChars
[in] specifying the maximum number of characters to be received.
szKeyFileOrString
[in] specifying either the name of file containing the key or a string containing the key in PEM format.
nOptions
[in] not used in this release. Specify zero.

Returns (VBA/C)

If successful, the return value is the number of characters in or required for the output string; otherwise it returns a negative error code.

VBA Wrapper Syntax

Public Function eccReadPublicKey (szKeyFileOrString As String, Optional nOptions As Long = 0) As String

.NET Equivalent

Ecc.ReadPublicKey Method

C++ (STL) Equivalent

static std::string dipki::Ecc::ReadPublicKey (std::string keyFileOrString)

Python Equivalent

static Ecc.read_public_key(keyfileorstr)

Remarks

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).

Example (VBA core function)

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)

Example (VBA wrapper function)

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))

See Also

ECC_ReadPrivateKey ECC_QueryKey

[Contents] [Index]

[PREV: ECC_ReadPrivateKey...]   [Contents]   [Index]   
   [NEXT: ECC_SaveEncKey...]

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