CryptoSys PKI Pro Manual

SIG_VerifyData

Verify a signature value over data in a byte array.

VBA/VB6 Syntax

Public Declare Function SIG_VerifyData Lib "diCrPKI.dll" (ByVal strSignature As String, ByRef lpData As Byte, ByVal nDataLen As Long, ByVal strCertOrKeyFile As String, ByVal strAlgName As String, ByVal nOptions As Long) As Long

nRet = SIG_VerifyData(strSignature, lpData(0), nDataLen, strCertOrKeyFile, strAlgName, nOptions)

C/C++ Syntax

long __stdcall SIG_VerifyData(const char *szSignature, const unsigned char *lpData, long nDataLen, const char *szCertOrKeyFile, const char *szAlgName, long nOptions);

Parameters

szSignature
[in] string containing the signature value encoded in base64.
lpData
[in] byte array containing the input data to be verified.
nDataLen
[in] specifying the length of the input data in bytes.
szCertOrKeyFile
[in] specifying the X.509 certificate or public key file (or a string containing the certificate or key in PEM format or base64 representation).
szAlgName
[in] specifying the signature algorithm (case insensitive):
"sha1WithRSAEncryption" (default)
"sha224WithRSAEncryption"
"sha256WithRSAEncryption"
"sha384WithRSAEncryption"
"sha512WithRSAEncryption"
"md5WithRSAEncryption"
"ecdsaWithSHA1"
"ecdsaWithSHA224"
"ecdsaWithSHA256"
"ecdsaWithSHA384"
"ecdsaWithSHA512"
"RSA-PSS-SHA1"
"RSA-PSS-SHA224"
"RSA-PSS-SHA256"
"RSA-PSS-SHA384"
"RSA-PSS-SHA512"
"Ed25519" [New in v20.0] (see Remarks)
"Ed448" [New in v22.0] (see Remarks)
or "" to use the signature algorithm flag in nOptions, see Specifying the signature algorithm in a SIG_ function.
nOptions
[in] Zero (0) for defaults.
PKI_SIG_USEDIGEST to pass the digest value of the data-to-be-verified as a byte array in the lpData parameter instead of the data itself.
PKI_MGF_MGF1SHA1 (RSA-PSS only) to force the MGF hash function to be SHA-1 (default = same as signature hash algorithm).

Returns (VBA/C)

Zero (0) if the signature is valid; otherwise it returns a negative error code.

VBA Wrapper Syntax

Public Function sigVerifyData (szSignature As String, lpData() As Byte, szCertOrKey As String, szAlgName As String, Optional nOptions As Long = 0) As Long

.NET Equivalent

Sig.VerifyData Method
Sig.VerifyDigest Method

C++ (STL) Equivalent

static bool dipki::Sig::VerifyData (const std::string &sigStr, const bvec_t &data, const std::string &certOrKey, Alg alg=Alg::Default, VerifyOpts opts=VerifyOpts::Default)
static Sig.digest_is_verified(sig, digest, certorkey, alg, verifyopts=VerifyOpts.DEFAULT)

Python Equivalent

static Sig.data_is_verified(sig, data, certorkey, alg, verifyopts=VerifyOpts.DEFAULT)
static Sig.digest_is_verified(sig, digest, certorkey, alg, verifyopts=VerifyOpts.DEFAULT)

Remarks

A signature value is considered valid if it can be decrypted by the public key in szCertOrKeyFile and the digest of the data matches the original digest of the data in the signature. The signature algorithm and hash algorithm used to create the signature value must be provided.

For RSA-PSS, the MGF hash algorithm is assumed to be the same as the signature hash algorithm (see RSA signature and encryption schemes). If the signature was created using mgf1SHA1 with a signature hash algorithm other than SHA-1, then you must add the option PKI_MGF_MGF1SHA1. Other combinations of signature hash algorithm/MGF hash algorithm are not supported.

The PKI_SIG_USEDIGEST option cannot be used with Ed25519 or Ed448. The data to be verified must be passed in toto to the verify function.

Example

Dim strSignature As String
Dim strData As String
Dim abData() As Byte
Dim nDataLen As Long
Dim strCertFile As String
Dim strAlgName As String
Dim nRet As Long

' Signature to be verified
strSignature = _
"YK1aePtKQDDsVCyJdM0V9VOE6DZVTO3ZoyLV9BNcYmep0glwxU5mUQcLAUTUOETImTIN2Pp4Gffr" & _
"xqdxUoczLshnXBNhg7P4ofge+WlBgmcTCnVv27LHHZpmdEbjTg6tnPMb+2b4FvMZ0LfkMKXyiRVTmG4A" & _
"NyAmHH6QIsDZ8R8="
' Data to be verified against signature = three-character ASCII string "abc"
strData = "abc"
strCertFile = "AliceRSASignByCarl.cer"
strAlgName = "sha1WithRSAEncryption"
' Convert ASCII string to byte array
abData = StrConv(strData, vbFromUnicode)
nDataLen = Len(strData)
' Verify the signature...
nRet = SIG_VerifyData(strSignature, abData(0), nDataLen, strCertFile, strAlgName, 0)
Debug.Print "SIG_VerifyData returns " & nRet & " (expecting 0)"

See Also

SIG_VerifyFile

[Contents] [Index]

[PREV: SIG_SignFile...]   [Contents]   [Index]   
   [NEXT: SIG_VerifyFile...]

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