Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15564

[RESOLVED] BCryptSignHash Error

$
0
0
To create an ECDSA Certificate Verify. we need a signed hash. Using a Private ECC Key Blob:
Code:

    If BCryptOpenAlgorithmProvider(hProv, hAlg, StrPtr("Microsoft Primitive Provider"), 0) <> 0 Then GoTo ReleaseHandles
    cbPrivBlob = GetbSize(bPrivateECCKey)
    If BCryptImportKeyPair(hProv, 0&, StrPtr("ECCPRIVATEBLOB"), hPrivKey, VarPtr(bPrivateECCKey(0)), cbPrivBlob, 0) <> 0 then GoTo ReleaseHandles
    'Get size of Signature
    lRet = BCryptSignHash(hPrivKey, ByVal 0, bTmp(0), GetbSize(bTmp), ByVal 0, 0, lLen, 0)
    'No error
    If lRet = 0 Then
        ReDim bVerify(lLen - 1)
        If BCryptSignHash(hPrivKey, ByVal 0, bTmp(0), GetbSize(bTmp), bVerify(0), GetbSize(bVerify), lLen, 0) <> 0 Then GoTo ReleaseHandles
    End If

produces a 64 byte signature for "ECDSA_P256". At the other end we are supposed to use the Public Key Blob to verify the sender has the private key:
Code:

    If BCryptOpenAlgorithmProvider(hProv, hAlg, StrPtr("Microsoft Primitive Provider"), 0) <> 0 Then GoTo ReleaseHandles
    cbPubBlob = GetbSize(bPublicECCKey)
    If BCryptImportKeyPair(hProv, 0&, StrPtr("ECCPUBLICBLOB"), hPubKey, VarPtr(bPublicECCKey(0)), cbPubBlob, 0) <> 0 then GoTo ReleaseHandles
    'Get size of Signature
    lRet = BCryptSignHash(hPubKey, ByVal 0, bTmp(0), GetbSize(bTmp), ByVal 0, 0, lLen, 0)
    'Returns error &HC0000000D
    If lRet = 0 Then
        ReDim bVerify(lLen - 1)
        If BCryptSignHash(hPubKey, ByVal 0, bTmp(0), GetbSize(bTmp), bVerify(0), GetbSize(bVerify), lLen, 0) <> 0 Then GoTo ReleaseHandles
    End If

produces a STATUS_INVALID_PARAMETER error. The Private and Public keys were produced by OpenSSL, less the leading "No Compression byte &H04).

Anyone have any idea what the problem is?

J.A. Coutts

Viewing all articles
Browse latest Browse all 15564

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>