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); keyFile.open(QFile::WriteOnly); 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. 인증서 서명 요청을 인증 기관에서 서명해야 하는 경우, 요청 데이터를 사용해야 합니다.
QByteArray certificateSigningRequestData = csr.createRequest(key);
2. 인증 기관이 없는 경우 요청에 직접 서명해야 합니다.
QByteArray selfSignedCertificateData = csr.createSelfSignedCertificate(key);
파일:
© 2025 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.