Compute a signature value over data in a file.
Public Declare Function SIG_SignFile Lib "diCrPKI.dll" (ByVal strOutput As String, ByVal nOutChars As Long, ByVal strDataFile As String, ByVal strKeyFile As String, ByVal strPassword As String, ByVal strAlgName As String, ByVal nOptions As Long) As Long
nRet = SIG_SignFile(strOutput, nOutChars, strDataFile, strKeyFile, strPassword, strAlgName, nOptions)
long __stdcall SIG_SignFile(char *szOutput, long nOutChars, const char *szDataFile, const char *szKeyFile, const char *szPassword, const char *szAlgName, long nOptions);
""
if not required.r||s
)
hLen
, the length of the output of the hash function (default).If successful, the return value is the number of characters in or required for the output string; otherwise it returns a negative error code.
Public Function sigSignFile
(szDataFile As String, szKeyFile As String, szPassword As String, szAlgName As String, Optional nOptions As Long = 0) As String
static std::string dipki::Sig::SignFile (const std::string &dataFile, const std::string &keyFileOrString, const std::string &password="", Alg alg=Alg::Default, Encoding encoding=Encoding::Base64, SigOptions opts=SigOptions::None)
static Sig.sign_file(datafile, keyfile, password, alg, opts=Opts.DEFAULT, encoding=Encoding.DEFAULT)
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.
This function is identical to SIG_SignData
except the data to be signed is in a file.
The Ed25519 and Ed448 signature algorithms are not available with this function. To sign using Ed25519 or Ed448, read in the file to a byte array and use SIG_SignData.
Dim strSignature As String Dim strDataFile As String Dim strKeyFile As String Dim strPassword As String Dim nChars As Long Dim nOption As Long 'Input data = file containing the three bytes 'a', 'b', 'c' strDataFile = "abc.txt" strKeyFile = "AlicePrivRSASign.p8e" strPassword = "password" ' CAUTION: do not hard-code passwords! nOption = PKI_SIG_SHA256RSA ' Use option instead of string ' Find required length of output string nChars = SIG_SignFile("", 0, strDataFile, strKeyFile, strPassword, "", nOption) Debug.Print "SIG_SignFile returns " & nChars & " (expected >0)" ' Allocate memory for output string strSignature = String(nChars, " ") nChars = SIG_SignFile(strSignature, Len(strSignature), strDataFile, strKeyFile, strPassword, "", nOption) ' Output base64 signature value Debug.Print "SIG=" & strSignature
This uses Alice's encrypted private key to sign a file using sha256WithRSAEncryption. The output should be
SIG_SignFile returns 172 (expected >0) SIG=tLy6hJadL4w9JI/A/qLCG0V...peD1VHSzgu/qirjOaA=
Dim strSig As String
strSig = sigSignFile("abc.txt", "AlicePrivRSASign.p8e", "password", "", PKI_SIG_SHA256RSA)
Debug.Print "SIG=" & strSig
Debug.Print "OK =" & "tLy6hJadL4w9JI/A/qLCG0V...peD1VHSzgu/qirjOaA="