이 페이지에서

Qt OPC UA X509 지원

키 및 인증서 서명 요청을 생성하는 방법을 보여줍니다.

이 예제는 클라이언트 애플리케이션이 자체 서명된 인증서를 생성하거나 인증서 서명 요청을 생성하는 방법을 보여줍니다.

RSA 키 생성

먼저 RSA 키를 생성합니다:

QOpcUaKeyPair key;
key.generateRsaKey(QOpcUaKeyPair::RsaKeyStrength::Bits2048);

추후 사용을 위해 개인 키를 파일에 저장할 수 있습니다:

QByteArray keyData = key.privateKeyToByteArray(QOpcUaKeyPair::Cipher::Unencrypted, QString());

QFile keyFile(u"privateKey.pem"_s);
if (!keyFile.open(QFile::WriteOnly))
    return EXIT_FAILURE;

keyFile.write(keyData);
keyFile.close();

인증서 서명 요청 생성

다음으로, 인증서 서명 요청을 생성합니다. 또한 인증서의 주체를 설정하고 OPC UA에 필요한 모든 확장 기능을 추가해야 합니다.

QOpcUaX509CertificateSigningRequest csr;

// Set the subject of the certificate
QOpcUaX509DistinguishedName dn;
dn.setEntry(QOpcUaX509DistinguishedName::Type::CommonName, u"QtOpcUaViewer"_s);
dn.setEntry(QOpcUaX509DistinguishedName::Type::CountryName, u"DE"_s);
dn.setEntry(QOpcUaX509DistinguishedName::Type::LocalityName, u"Berlin"_s);
dn.setEntry(QOpcUaX509DistinguishedName::Type::StateOrProvinceName, u"Berlin"_s);
dn.setEntry(QOpcUaX509DistinguishedName::Type::OrganizationName, u"The Qt Company"_s);
csr.setSubject(dn);

이제 두 가지 옵션이 있습니다:

1. 인증서 서명 요청에 대해 인증 기관(CA)의 서명을 받아야 하는 경우, 요청 데이터를 사용해야 합니다.

QByteArray certificateSigningRequestData = csr.createRequest(key);

2. 인증 기관이 없는 경우, 요청에 자체 서명을 해야 합니다.

QByteArray selfSignedCertificateData = csr.createSelfSignedCertificate(key);

예제 프로젝트 @ code.qt.io

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.