QSslCertificate 类

The QSslCertificate 类为 X509 证书提供方便 API。 更多...

头: #include <QSslCertificate>
Since: Qt 4.3

注意: 此类的所有函数 可重入 .

公共类型

enum SubjectInfo { Organization, CommonName, LocalityName, OrganizationalUnitName, CountryName, StateOrProvinceName }

公共函数

QSslCertificate (QIODevice * device , QSsl::EncodingFormat format = QSsl::Pem)
QSslCertificate (const QByteArray & data = QByteArray(), QSsl::EncodingFormat format = QSsl::Pem)
QSslCertificate (const QSslCertificate & other )
~QSslCertificate ()
QMultiMap<QSsl::AlternateNameEntryType, QString> alternateSubjectNames () const
void clear ()
QByteArray digest (QCryptographicHash::Algorithm algorithm = QCryptographicHash::Md5) const
QDateTime effectiveDate () const
QDateTime expiryDate () const
Qt::HANDLE handle () const
bool isNull () const
bool isValid () const
QString issuerInfo (SubjectInfo subject ) const
QString issuerInfo (const QByteArray & tag ) const
QSslKey publicKey () const
QByteArray serialNumber () const
QString subjectInfo (SubjectInfo subject ) const
QString subjectInfo (const QByteArray & tag ) const
QByteArray toDer () const
QByteArray toPem () const
QByteArray version () const
bool operator!= (const QSslCertificate & other ) const
QSslCertificate & operator= (const QSslCertificate & other )
bool operator== (const QSslCertificate & other ) const

静态公共成员

QList<QSslCertificate> fromData (const QByteArray & data , QSsl::EncodingFormat format = QSsl::Pem)
QList<QSslCertificate> fromDevice (QIODevice * device , QSsl::EncodingFormat format = QSsl::Pem)
QList<QSslCertificate> fromPath (const QString & path , QSsl::EncodingFormat format = QSsl::Pem, QRegExp::PatternSyntax syntax = QRegExp::FixedString)

详细描述

The QSslCertificate 类为 X509 证书提供方便 API。

QSslCertificate stores an X509 certificate, and is commonly used to verify the identity and store information about the local host, a remotely connected peer, or a trusted third party Certificate Authority.

There are many ways to construct a QSslCertificate . The most common way is to call QSslSocket::peerCertificate (), which returns a QSslCertificate object, or QSslSocket::peerCertificateChain (), which returns a list of them. You can also load certificates from a DER (binary) or PEM (Base64) encoded bundle, typically stored as one or more local files, or in a Qt Resource.

可以调用 isNull () to check if your certificate is null. By default, QSslCertificate constructs a null certificate. To check if the certificate is valid, call isValid (). A null certificate is invalid, but an invalid certificate is not necessarily null. If you want to reset all contents in a certificate, call clear ().

After loading a certificate, you can find information about the certificate, its subject, and its issuer, by calling one of the many accessor functions, including version (), serialNumber (), issuerInfo () 和 subjectInfo (). You can call effectiveDate () 和 expiryDate () to check when the certificate starts being effective and when it expires. The publicKey () function returns the certificate subject's public key as a QSslKey 。可以调用 issuerInfo () 或 subjectInfo () to get detailed information about the certificate issuer and its subject.

在内部, QSslCertificate is stored as an X509 structure. You can access this handle by calling handle (), but the results are likely to not be portable.

另请参阅 QSslSocket , QSslKey , QSslCipher ,和 QSslError .

成员类型文档编制

enum QSslCertificate:: SubjectInfo

Describes keys that you can pass to QSslCertificate::issuerInfo () 或 QSslCertificate::subjectInfo () to get information about the certificate issuer or subject.

常量 描述
QSslCertificate::Organization 0 "O" The name of the organization.
QSslCertificate::CommonName 1 "CN" The common name; most often this is used to store the host name.
QSslCertificate::LocalityName 2 "L" The locality.
QSslCertificate::OrganizationalUnitName 3 "OU" The organizational unit name.
QSslCertificate::CountryName 4 "C" The country.
QSslCertificate::StateOrProvinceName 5 "ST" The state or province.

成员函数文档编制

QSslCertificate:: QSslCertificate ( QIODevice * device , QSsl::EncodingFormat format = QSsl::Pem)

构造 QSslCertificate by reading format encoded data from device and using the first certificate found. You can later call isNull () to see if device contained a certificate, and if this certificate was loaded successfully.

QSslCertificate:: QSslCertificate (const QByteArray & data = QByteArray(), QSsl::EncodingFormat format = QSsl::Pem)

构造 QSslCertificate by parsing the format encoded data and using the first available certificate found. You can later call isNull () to see if data contained a certificate, and if this certificate was loaded successfully.

QSslCertificate:: QSslCertificate (const QSslCertificate & other )

Constructs an identical copy of other .

QSslCertificate:: ~QSslCertificate ()

销毁 QSslCertificate .

QMultiMap < QSsl::AlternateNameEntryType , QString > QSslCertificate:: alternateSubjectNames () const

Returns the list of alternative subject names for this certificate. The alternate subject names typically contain host names, optionally with wildcards, that are valid for this certificate.

These names are tested against the connected peer's host name, if either the subject information for CommonName doesn't define a valid host name, or the subject info name doesn't match the peer's host name.

另请参阅 subjectInfo ().

void QSslCertificate:: clear ()

Clears the contents of this certificate, making it a null certificate.

另请参阅 isNull ().

QByteArray QSslCertificate:: digest ( QCryptographicHash::Algorithm algorithm = QCryptographicHash::Md5) const

Returns a cryptographic digest of this certificate. By default, an MD5 digest will be generated, but you can also specify a custom algorithm .

QDateTime QSslCertificate:: effectiveDate () const

Returns the date-time that the certificate becomes valid, or an empty QDateTime if this is a null certificate.

另请参阅 expiryDate ().

QDateTime QSslCertificate:: expiryDate () const

Returns the date-time that the certificate expires, or an empty QDateTime if this is a null certificate.

另请参阅 effectiveDate ().

[static] QList < QSslCertificate > QSslCertificate:: fromData (const QByteArray & data , QSsl::EncodingFormat format = QSsl::Pem)

Searches for and parses all certificates in data that are encoded in the specified format and returns them in a list of certificates.

另请参阅 fromDevice ().

[static] QList < QSslCertificate > QSslCertificate:: fromDevice ( QIODevice * device , QSsl::EncodingFormat format = QSsl::Pem)

Searches for and parses all certificates in device that are encoded in the specified format and returns them in a list of certificates.

另请参阅 fromData ().

[static] QList < QSslCertificate > QSslCertificate:: fromPath (const QString & path , QSsl::EncodingFormat format = QSsl::Pem, QRegExp::PatternSyntax syntax = QRegExp::FixedString)

Searches all files in the path for certificates encoded in the specified format and returns them in a list. must be a file or a pattern matching one or more files, as specified by syntax .

范例:

foreach (const QSslCertificate &cert, QSslCertificate::fromPath("C:/ssl/certificate.*.pem", QSsl::Pem,
                                                         QRegExp::Wildcard)) {
    qDebug() << cert.issuerInfo(QSslCertificate::Organization);
}
					

另请参阅 fromData ().

Qt::HANDLE QSslCertificate:: handle () const

Returns a pointer to the native certificate handle, if there is one, or a null pointer otherwise.

You can use this handle, together with the native API, to access extended information about the certificate.

警告: Use of this function has a high probability of being non-portable, and its return value may vary from platform to platform or change from minor release to minor release.

bool QSslCertificate:: isNull () const

Returns true if this is a null certificate (i.e., a certificate with no contents); otherwise returns false.

默认情况下, QSslCertificate constructs a null certificate.

另请参阅 isValid () 和 clear ().

bool QSslCertificate:: isValid () const

Returns true if this certificate is valid; otherwise returns false.

Note: Currently, this function checks that the current data-time is within the date-time range during which the certificate is considered valid, and checks that the certificate is not in a blacklist of fraudulent certificates.

另请参阅 isNull ().

QString QSslCertificate:: issuerInfo ( SubjectInfo subject ) const

Returns the issuer information for the subject from the certificate, or an empty string if there is no information for subject in the certificate.

另请参阅 subjectInfo ().

QString QSslCertificate:: issuerInfo (const QByteArray & tag ) const

Returns the issuer information for tag from the certificate, or an empty string if there is no information for tag in the certificate.

另请参阅 subjectInfo ().

QSslKey QSslCertificate:: publicKey () const

Returns the certificate subject's public key.

QByteArray QSslCertificate:: serialNumber () const

Returns the certificate's serial number string in decimal format. In case the serial number cannot be converted to decimal format (i.e. if it is bigger than 4294967295, which means it does not fit into 4 bytes), its hexadecimal version is returned.

QString QSslCertificate:: subjectInfo ( SubjectInfo subject ) const

Returns the information for the subject , or an empty string if there is no information for subject in the certificate.

另请参阅 issuerInfo ().

QString QSslCertificate:: subjectInfo (const QByteArray & tag ) const

Returns the subject information for tag , or an empty string if there is no information for tag in the certificate.

另请参阅 issuerInfo ().

QByteArray QSslCertificate:: toDer () const

Returns this certificate converted to a DER (binary) encoded representation.

QByteArray QSslCertificate:: toPem () const

Returns this certificate converted to a PEM (Base64) encoded representation.

QByteArray QSslCertificate:: version () const

返回证书的版本字符串。

bool QSslCertificate:: operator!= (const QSslCertificate & other ) const

Returns true if this certificate is not the same as other ;否则返回 false。

QSslCertificate & QSslCertificate:: operator= (const QSslCertificate & other )

Copies the contents of other into this certificate, making the two certificates identical.

bool QSslCertificate:: operator== (const QSslCertificate & other ) const

Returns true if this certificate is the same as other ;否则返回 false。