Creates a PKCS #10 certificate signing request (CSR) using the subject's private key file.
Public Declare Function X509_CertRequest Lib "diCrPKI.dll"
(ByVal strReqFile As String, ByVal strPriKeyFile As String,
ByVal strDistName As String, ByVal strExtensions As String,
ByVal strPassword As String, ByVal nOptions As Long) As Long
nRet = X509_CertRequest(strReqFile,
strPriKeyFile, strDistName, strExtensions, strPassword, nOptions)
long __stdcall X509_CertRequest(const char *szNewReqFile, const char *szPriKeyFile, const char *szDistName, const char *szExtensions, const char *szPassword, long nOptions);
extensionRequest
element.
See X.509 Extensions Parameter.
[New in v10.0].
""
if key not encrypted [New in v12.0].sha1WithRSAEncryption
(default - CAUTION)sha224WithRSAEncryption
sha256WithRSAEncryption
[minimum recommended]sha384WithRSAEncryption
sha512WithRSAEncryption
md5WithRSAEncryption
[legacy, not recommended]md2WithRSAEncryption
[legacy, definitely not recommended]RSA-PSS-SHA1
RSA-PSS-SHA224
RSA-PSS-SHA256
RSA-PSS-SHA384
RSA-PSS-SHA512
ecdsaWithSHA1
ecdsaWithSHA224
ecdsaWithSHA256
ecdsaWithSHA384
ecdsaWithSHA512
Ed25519
[New in v20.0]Ed448
[New in v22.0]UTF8String
(default = PrintableString)If successful, the return value is zero; otherwise it returns a nonzero error code.
static int dipki::X509::CertRequest (const std::string &newFile, const std::string &priKeyFile, const std::string &password, const std::string distName, const std::string extns="", SigAlg sigAlg=SigAlg::Default, CsrOptions opts=CsrOptions::Default_CsrOpt)
static X509.cert_request(newcsrfile, prikeyfile, password, distname, extns="", sigalg=0, opts=0)
The default output is a base64 PEM format CSR file ready for sending to the issuer of your choice. Any existing file of the same name will be overwritten without warning.
This example will create a new certificate request with filename myreq.p10.txt
.
for the subject with common name "myuser", etc.
The subject's encrypted private key is in the file mykey.p8e
and has
the password "password". The certificate request will be signed using the subject's private key
using the default sha1WithRSAEncryption
algorithm.
Dim nRet As Long
nRet = X509_CertRequest("myreq.p10.txt", "mykey.p8e", _
"CN=myuser;O=Test Org;C=AU;L=Sydney;S=NSW", "", "password", 0)
If nRet <> 0 Then
Debug.Print nRet & " " & pkiGetLastError()
Else
Debug.Print "Success"
End If
This should produce an output file similar to:
-----BEGIN CERTIFICATE REQUEST----- MIIBGjCBxQIBADBQMQ8wDQYDVQQDEwZteXVzZXIxETAPBgNVBAoTCFRlc3QgT3Jn MQswCQYDVQQGEwJBVTEPMA0GA1UECBMGU3lkbmV5MQwwCgYDVQQHEwNOU1cwWjAN BgkqhkiG9w0BAQEFAANJADBGAkEAvdci5sKarpPzljBVVxJfGEfBOvjxlgFYOg1x xEEG9Xbilxgl3kTfIrA4KqNmGdEKPksbHXNuxXkwaaAld3bBHQIBA6ASMBAGCisG AQQBgjcCAQ4xAjAAMA0GCSqGSIb3DQEBBQUAA0EAtqie6G31yRcwJljEDdbeYd+w 5FvLd631nL//JuISFv6fl9B30WtHQtI1wuryVYZ6fRWZPpu9jZjs5gsnKFtiUg== -----END CERTIFICATE REQUEST-----
The next example duplicates the certificate request in Sections 3.1 to 3.3 of "Some Examples of the PKCS Standards"
[PKCS-EX].
It uses the 508-bit private key to sign the request, which is stored in the file rsa508.p8e
with the password "password". The signature algorithm is md2WithRSAEncryption
and the output is in binary format. To reproduce this example requires the non-strict "kludge".
The output should exactly match the CertificationRequest value in section 3.2 of PKCS-EX.
Dim nRet As Long
nRet = X509_CertRequest("pkcs_ex_req.bin", "rsa508.p8e", _
"C=US;O=Example Organization;CN=Test User 1", "", "password", _
PKI_SIG_MD2RSA + PKI_X509_FORMAT_BIN + PKI_X509_REQ_KLUDGE)
If nRet <> 0 Then
Debug.Print nRet & " " & pkiGetLastError()
Else
Debug.Print "Success"
End If
The latter example is just to demonstrate the replication of an old but known test vector, not to demonstrate good practice.