Computes the hash code of an "internal" ECC public or private key string.
Public Declare Function ECC_KeyHashCode Lib "diCrPKI.dll"
(ByVal strKeyString As String) As Long
nRet = ECC_KeyHashCode(strKeyString)
long __stdcall ECC_KeyHashCode(const char *szKeyString);
A 32-bit hash code for the key, or zero on error.
Public Function eccKeyHashCode
(szIntKeyString As String) As Long
static uint32_t dipki::Ecc::KeyHashCode (std::string intKeyString)
static Ecc.key_hashcode(intkeystr)
Use this function to compare internal key strings.
The hash code value will be the same for a given key.
The hash code is computed to an internal algorithm and may return any integer value
between -2,147,483,648 and 2,147,483,647.
If the key string is invalid, the return value is zero and a nonzero error code will be set (use PKI_ErrorCode
to check).
There is a very small chance (one in 4 billion) that a valid key string returns a hash code of zero.
Dim nRet As Long Dim nChars As Long Dim strPubKeyFile As String Dim strPriKeyFile As String Dim strIntKey As String Dim strPassword As String strPubKeyFile = "CA_ECC_P256.pub" strPriKeyFile = "CA_ECC_P256.p8e" strPassword = "password" ' 1. Read in private key to internal key string Debug.Print "FILE: " & strPriKeyFile ' 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) ' Note: internal key string is only valid for the current session ' But the Key Hash Code is always the same nRet = ECC_KeyHashCode(strIntKey) Debug.Print "KeyHashCodePrivate=0x" & Hex(nRet) ' 2. Read in public key to internal string Debug.Print "FILE: " & strPubKeyFile ' Find required length of internal key string nChars = ECC_ReadPublicKey("", 0, strPubKeyFile, 0) Debug.Print "ECC_ReadPublicKey returns " & nChars & " (expected +ve)" ' Dimension the string to receive output strIntKey = String(nChars, " ") ' Read it in nChars = ECC_ReadPublicKey(strIntKey, Len(strIntKey), strPubKeyFile, 0) ' The public and private Key Hash Codes should match nRet = ECC_KeyHashCode(strIntKey) Debug.Print "KeyHashCodePublic=0x" & Hex(nRet)
FILE: CA_ECC_P256.p8e ECC_ReadPrivateKey returns 100 (expected +ve) KeyHashCodePrivate=0x37210904 FILE: CA_ECC_P256.pub ECC_ReadPublicKey returns 124 (expected +ve) KeyHashCodePublic=0x37210904