QOpcUaX509CertificateSigningRequest Class

QOpcUaX509CertificateSigningRequest create a certificate signing request. 更多...

头: #include <QOpcUaX509CertificateSigningRequest>
CMake: find_package(Qt6 REQUIRED COMPONENTS OpcUa)
target_link_libraries(mytarget PRIVATE Qt6::OpcUa)
qmake: QT += opcua

公共类型

enum class 编码 { PEM, DER }
enum class MessageDigest { SHA256 }

公共函数

QOpcUaX509CertificateSigningRequest ()
~QOpcUaX509CertificateSigningRequest ()
void addExtension (QOpcUaX509Extension * extension )
QByteArray createRequest (const QOpcUaKeyPair & privateKey )
QByteArray createSelfSignedCertificate (const QOpcUaKeyPair & privateKey , int validityInDays = 365)
QOpcUaX509CertificateSigningRequest::Encoding encoding () const
QOpcUaX509CertificateSigningRequest::MessageDigest messageDigest () const
void setEncoding (QOpcUaX509CertificateSigningRequest::Encoding encoding )
void setMessageDigest (QOpcUaX509CertificateSigningRequest::MessageDigest digest )
void setSubject (const QOpcUaX509DistinguishedName & subject )
const QOpcUaX509DistinguishedName & subject () const

详细描述

This class is currently available as a Technology Preview, and therefore the API and functionality provided by the class may be subject to change at any time without prior notice.

Before actually creating the singing request data, any extension needed for that specific request has to be added. Current supported extensions are SubjectAlternativeName, BasicConstrains, KeyUsage and ExtendedKeyUsage.

// Generate key
QOpcUaKeyPair key;
key.generateRsaKey(QOpcUaKeyPair::RsaKeyStrength::Bits1024);
QOpcUaX509CertificateSigningRequest csr;
QOpcUaX509DistinguishedName dn;
dn.setEntry(QOpcUaX509DistinguishedName::Type::CommonName, "QtOpcUaViewer");
dn.setEntry(QOpcUaX509DistinguishedName::Type::CountryName, "DE");
dn.setEntry(QOpcUaX509DistinguishedName::Type::LocalityName, "Berlin");
dn.setEntry(QOpcUaX509DistinguishedName::Type::StateOrProvinceName, "Berlin");
dn.setEntry(QOpcUaX509DistinguishedName::Type::OrganizationName, "The Qt Company");
csr.setSubject(dn);
QOpcUaX509ExtensionSubjectAlternativeName *san = new QOpcUaX509ExtensionSubjectAlternativeName;
san->addData(QOpcUaX509ExtensionSubjectAlternativeName::Type::DNS, "foo.com");
san->addData(QOpcUaX509ExtensionSubjectAlternativeName::Type::DNS, "foo.com");
san->addData(QOpcUaX509ExtensionSubjectAlternativeName::Type::URI, "urn:foo.com:The%20Qt%20Company:QtOpcUaViewer");
san->setCritical(true);
csr.addExtension(san);
QOpcUaX509ExtensionBasicConstraints *bc = new QOpcUaX509ExtensionBasicConstraints;
bc->setCa(false);
bc->setCritical(true);
csr.addExtension(bc);
QOpcUaX509ExtensionKeyUsage *ku = new QOpcUaX509ExtensionKeyUsage;
ku->setCritical(true);
ku->setKeyUsage(QOpcUaX509ExtensionKeyUsage::KeyUsage::DigitalSignature);
ku->setKeyUsage(QOpcUaX509ExtensionKeyUsage::KeyUsage::NonRepudiation);
ku->setKeyUsage(QOpcUaX509ExtensionKeyUsage::KeyUsage::KeyEncipherment);
ku->setKeyUsage(QOpcUaX509ExtensionKeyUsage::KeyUsage::DataEncipherment);
ku->setKeyUsage(QOpcUaX509ExtensionKeyUsage::KeyUsage::CertificateSigning);
csr.addExtension(ku);
QOpcUaX509ExtensionExtendedKeyUsage *eku = new QOpcUaX509ExtensionExtendedKeyUsage;
eku->setCritical(true);
eku->setKeyUsage(QOpcUaX509ExtensionExtendedKeyUsage::KeyUsage::EmailProtection);
csr.addExtension(eku);
QByteArray csrData = csr.createRequest(key);
					

另请参阅 QOpcUaX509ExtensionSubjectAlternativeName , QOpcUaX509ExtensionBasicConstraints , QOpcUaX509ExtensionKeyUsage ,和 QOpcUaX509ExtensionKeyUsage .

成员类型文档编制

enum class QOpcUaX509CertificateSigningRequest:: 编码

This enum type specifies the encoding of the generated certificate siging request.

常量 描述
QOpcUaX509CertificateSigningRequest::Encoding::PEM 0 Using PEM encoding
QOpcUaX509CertificateSigningRequest::Encoding::DER 1 Using DER encoding

enum class QOpcUaX509CertificateSigningRequest:: MessageDigest

This enum type specifies the message digest to be used.

常量 描述
QOpcUaX509CertificateSigningRequest::MessageDigest::SHA256 0 Using the SHA256 message digest

成员函数文档编制

QOpcUaX509CertificateSigningRequest:: QOpcUaX509CertificateSigningRequest ()

Creates an empty certificate signing request.

QOpcUaX509CertificateSigningRequest:: ~QOpcUaX509CertificateSigningRequest ()

Destroys the request and frees all extensions.

void QOpcUaX509CertificateSigningRequest:: addExtension ( QOpcUaX509Extension * extension )

Adds a certificate extension to the request.

The ownership of the extension object will be transferred to this class.

另请参阅 QOpcUaX509ExtensionSubjectAlternativeName , QOpcUaX509ExtensionBasicConstraints , QOpcUaX509ExtensionKeyUsage ,和 QOpcUaX509ExtensionKeyUsage .

QByteArray QOpcUaX509CertificateSigningRequest:: createRequest (const QOpcUaKeyPair & privateKey )

Creates a certificate signing request to be the to a CA for signing. The private key in privateKey is used to sign the request. The request data is returned as a byte array in the encoding set by setEncoding ().

QByteArray QOpcUaX509CertificateSigningRequest:: createSelfSignedCertificate (const QOpcUaKeyPair & privateKey , int validityInDays = 365)

Creates a self-signed certificate from this request for immediate use. The private key in privateKey is used to sign the request. A validity in days can be specified in validityInDays . The request data is returned as a byte array in the encoding set by setEncoding ().

QOpcUaX509CertificateSigningRequest::Encoding QOpcUaX509CertificateSigningRequest:: encoding () const

Returns the used request encoding.

另请参阅 setEncoding ().

QOpcUaX509CertificateSigningRequest::MessageDigest QOpcUaX509CertificateSigningRequest:: messageDigest () const

Returns the used message digest.

另请参阅 setMessageDigest ().

void QOpcUaX509CertificateSigningRequest:: setEncoding ( QOpcUaX509CertificateSigningRequest::Encoding encoding )

Sets the used request encoding to encoding . The default request encoding is PEM.

另请参阅 encoding ().

void QOpcUaX509CertificateSigningRequest:: setMessageDigest ( QOpcUaX509CertificateSigningRequest::MessageDigest digest )

Sets the used message digest to digest . The default message digest is SHA256.

另请参阅 messageDigest ().

void QOpcUaX509CertificateSigningRequest:: setSubject (const QOpcUaX509DistinguishedName & subject )

设置 subject for this request. Without a subject it is not possible to generate the request.

另请参阅 subject ().

const QOpcUaX509DistinguishedName &QOpcUaX509CertificateSigningRequest:: subject () const

Returns the subject of this request.

另请参阅 setSubject ().