Verifies that a pair of "internal" ECC private and public key strings are matched.
Public Declare Function ECC_KeyMatch Lib "diCrPKI.dll"
(ByVal strPrivateKey As String, ByVal strPublicKey As String) As Long
nRet = ECC_KeyMatch(strPrivateKey, strPublicKey)
long __stdcall ECC_KeyMatch(const char *szPrivateKey, const char *szPublicKey);
If the pair of private and public keys match, the return value is zero (0). If the key strings are valid but not matched, the return value is NO_MATCH_ERROR (-21). If an error occurs, it returns a nonzero error code.
static bool dipki::Ecc::KeyMatch (const std::string &privateKey, const std::string &publicKey)
This function allows you to check that a private key file is matched with its corresponding public key. You must read the keys into "internal" key strings before comparing. Note that the return value for success is zero.
Dim strCurveName As String Dim strPriKeyHex As String Dim strPubKeyHex As String Dim strPriKeyInt As String Dim strPubKeyInt As String Dim r As Long ' Ref: https://www.ietf.org/archive/id/draft-ietf-cose-cbor-encoded-cert-20.html#appendix-A.1.4 strCurveName = "secp256r1" strPriKeyHex = "DC66B3415456D649429B53223DF7532B942D6B0E0842C30BCA4C0ACF91547BB2" strPubKeyHex = "02AE4CDB01F614DEFC7121285FDC7F5C6D1D42C95647F061BA0080DF678867845E" ' Read in keys to ephemeral internal representation strPriKeyInt = eccReadKeyByCurve(strPriKeyHex, strCurveName) strPubKeyInt = eccReadKeyByCurve(strPubKeyHex, strCurveName) ' Check that keys match r = ECC_KeyMatch(strPriKeyInt, strPubKeyInt) Debug.Print "ECC_KeyMatch returns " & r & " (expected 0)" Debug.Assert r = 0
ECC_KeyMatch returns 0 (expected 0)