QMessageAuthenticationCode Class
QMessageAuthenticationCode 클래스는 해시 기반의 메시지 인증 코드를 생성하는 방법을 제공합니다. 더 보기...
| 헤더: | #include <QMessageAuthenticationCode> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
참고: 이 클래스의 모든 함수는 재진입 가능합니다.
공개 함수
| QMessageAuthenticationCode(QCryptographicHash::Algorithm method, QByteArrayView key = {}) | |
(since 6.6) | QMessageAuthenticationCode(QMessageAuthenticationCode &&other) |
| ~QMessageAuthenticationCode() | |
| void | addData(QByteArrayView data) |
| bool | addData(QIODevice *device) |
| void | addData(const char *data, qsizetype length) |
| void | reset() |
| QByteArray | result() const |
(since 6.6) QByteArrayView | resultView() const |
| void | setKey(QByteArrayView key) |
(since 6.6) void | swap(QMessageAuthenticationCode &other) |
(since 6.6) QMessageAuthenticationCode & | operator=(QMessageAuthenticationCode &&other) |
정적 공용 멤버
| QByteArray | hash(QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method) |
(since 6.8) QByteArrayView | hashInto(QSpan<char> buffer, QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method) |
(since 6.8) QByteArrayView | hashInto(QSpan<char> buffer, QSpan<const QByteArrayView> messageParts, QByteArrayView key, QCryptographicHash::Algorithm method) |
(since 6.8) QByteArrayView | hashInto(QSpan<std::byte> buffer, QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method) |
(since 6.8) QByteArrayView | hashInto(QSpan<std::byte> buffer, QSpan<const QByteArrayView> messageParts, QByteArrayView key, QCryptographicHash::Algorithm method) |
(since 6.8) QByteArrayView | hashInto(QSpan<uchar> buffer, QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method) |
(since 6.8) QByteArrayView | hashInto(QSpan<uchar> buffer, QSpan<const QByteArrayView> messageParts, QByteArrayView key, QCryptographicHash::Algorithm method) |
상세 설명
QMessageAuthenticationCode 클래스를 사용하여 해시 기반 메시지 인증 코드(HMAC)를 생성할 수 있습니다. 이 클래스는 QCryptographicHash 에 정의된 모든 암호 해시 알고리즘을 지원합니다( QCryptographicHash::Algorithm 도 참조하십시오).
메시지 인증 코드를 생성하려면 생성자에 적절한 해시 알고리즘과 비밀 키를 전달하십시오. 그런 다음 addData()를 한 번 이상 호출하여 메시지 데이터를 처리하십시오. 전체 메시지 처리가 완료된 후, result() 함수를 통해 최종 인증 코드를 가져옵니다.
QByteArray key = "key";
QByteArray message = "The quick brown fox jumps over the lazy dog";
...
QMessageAuthenticationCode code(QCryptographicHash::Sha256, key);
code.addData(message);
code.result().toHex(); // returns "f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8"위와 같은 간단한 경우에는 정적 함수인 hash()을 사용할 수도 있습니다:
QMessageAuthenticationCode::hash(message, key, QCryptographicHash::Sha256).toHex();참고: HMAC의 암호화강도는 비밀 키의 크기와 기본이 되는 해시 함수의 보안성에 따라 달라집니다.
QCryptographicHash 및 QCryptographicHash::Algorithm도 참조하십시오 .
멤버 함수 문서
[explicit] QMessageAuthenticationCode::QMessageAuthenticationCode(QCryptographicHash::Algorithm method, QByteArrayView key = {})
method 메서드와 키 key 를 사용하여 데이터로부터 암호학적 해시를 생성하는 데 사용할 수 있는 객체를 생성합니다.
참고: Qt 6.6 이전버전에서는 이 함수가 인자로 QByteArrayView 대신 QByteArray 를 사용했습니다. 컴파일 오류가 발생하는 경우, 이는 코드에서 QByteArray 로 암시적으로 변환될 수 있지만 QByteArrayView 로는 변환될 수 없는 객체를 전달하고 있기 때문입니다. 해당 인자를 QByteArray{~~~} 로 감싸서 형 변환을 명시적으로 지정하십시오. 이는 이전 Qt 버전과 역호환됩니다.
[noexcept, since 6.6] QMessageAuthenticationCode::QMessageAuthenticationCode(QMessageAuthenticationCode &&other)
other 에서 새로운 QMessageAuthenticationCode 객체를 이동 생성합니다.
참고: 이동된원본 객체 ` other `는 부분적으로 형성된 상태가 되며, 이 상태에서는 소멸 및 새 객체 할당만이 유효한 연산입니다.
이 함수는 Qt 6.6에서 도입되었습니다.
[noexcept] QMessageAuthenticationCode::~QMessageAuthenticationCode()
객체를 삭제합니다.
[noexcept] void QMessageAuthenticationCode::addData(QByteArrayView data)
메시지에 data 를 추가합니다.
참고: Qt 6.6 이전버전에서는 이 함수가 인수를 QByteArrayView 가 아닌 QByteArray 로 받아들였습니다. 컴파일 오류가 발생하는 경우, 코드가 QByteArray 로 암시적으로 변환될 수 있지만 QByteArrayView 로는 변환될 수 없는 객체를 전달하고 있기 때문입니다. 해당 인수를 QByteArray{~~~} 로 감싸서 형 변환을 명시적으로 지정하십시오. 이렇게 하면 이전 Qt 버전과의 하위 호환성을 유지할 수 있습니다.
resultView() 및 result()도 참조하십시오 .
bool QMessageAuthenticationCode::addData(QIODevice *device)
열려 있는 QIODevice device 에서 데이터가 끝날 때까지 읽은 후 이를 message에 추가합니다. 읽기가 성공하면 true 를 반환합니다.
참고: device 는 이미 열려 있어야 합니다.
void QMessageAuthenticationCode::addData(const char *data, qsizetype length)
data 의 처음 length 자까지를 메시지에 추가합니다.
이 함수는 오버로드된 함수입니다.
[static] QByteArray QMessageAuthenticationCode::hash(QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method)
키 key 와 메서드 method 를 사용하여 메시지 message 에 대한 인증 코드를 반환합니다.
참고: Qt 6.6 이전버전에서는 이 함수가 QByteArrayView 이 아닌 QByteArray 을 인수로 받았습니다. 컴파일 오류가 발생하는 경우, 코드에서 QByteArray 으로는 암시적으로 변환될 수 있지만 QByteArrayView 으로는 변환될 수 없는 객체를 전달하고 있기 때문입니다. 해당 인수를 QByteArray{~~~} 로 감싸서 형 변환을 명시적으로 지정하십시오. 이는 이전 Qt 버전과 하위 호환됩니다.
hashInto()도 참조하십시오 .
[static noexcept, since 6.8] QByteArrayView QMessageAuthenticationCode::hashInto(QSpan<char> buffer, QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method)
[static noexcept, since 6.8] QByteArrayView QMessageAuthenticationCode::hashInto(QSpan<char> buffer, QSpan<const QByteArrayView> messageParts, QByteArrayView key, QCryptographicHash::Algorithm method)
[static noexcept, since 6.8] QByteArrayView QMessageAuthenticationCode::hashInto(QSpan<std::byte> buffer, QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method)
[static noexcept, since 6.8] QByteArrayView QMessageAuthenticationCode::hashInto(QSpan<std::byte> buffer, QSpan<const QByteArrayView> messageParts, QByteArrayView key, QCryptographicHash::Algorithm method)
[static noexcept, since 6.8] QByteArrayView QMessageAuthenticationCode::hashInto(QSpan<uchar> buffer, QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method)
[static noexcept, since 6.8] QByteArrayView QMessageAuthenticationCode::hashInto(QSpan<uchar> buffer, QSpan<const QByteArrayView> messageParts, QByteArrayView key, QCryptographicHash::Algorithm method)
키 key 와 메서드 method 를 사용하여 메시지의 인증 코드(message 또는 QSpan 오버로드의 경우 messageParts 의 연결 문자열)를 반환합니다.
반환 값은 buffer 의 하위 스팬이 됩니다. 단, buffer 의 크기가 충분하지 않은 경우에는 null QByteArrayView 이 반환됩니다.
이 함수들은 Qt 6.8에서 도입되었습니다.
hash()도 참조하십시오 .
[noexcept] void QMessageAuthenticationCode::reset()
메시지 데이터를 초기화합니다. 이 함수를 호출해도 키에는 영향을 미치지 않습니다.
QByteArray QMessageAuthenticationCode::result() const
최종 인증 코드를 반환합니다.
resultView() 및 QByteArray::toHex()도 참조하십시오 .
[noexcept, since 6.6] QByteArrayView QMessageAuthenticationCode::resultView() const
최종 해시 값을 반환합니다.
반환된 뷰는 QMessageAuthenticationCode 객체가 다른 방법으로 수정되지 않는 한 유효하다는 점에 유의하십시오.
이 함수는 Qt 6.6에서 도입되었습니다.
result()도 참조하십시오 .
[noexcept] void QMessageAuthenticationCode::setKey(QByteArrayView key)
key 의 비밀값을 설정합니다. 이 함수를 호출하면 객체의 상태가 자동으로 재설정됩니다.
최적의 성능을 위해, 이 함수는 활성 키를 변경할 때만 호출하고, 다음과 같이 초기 키를 설정하는 데는 사용하지 마십시오.
QMessageAuthenticationCode mac(method);
mac.setKey(key); // does extra work
use(mac);초기 키는 생성자 인자로 전달하는 것이 좋습니다:
QMessageAuthenticationCode mac(method, key); // OK, optimal
use(mac);키를 알 때까지 QMessageAuthenticationCode 의 생성을 지연시키려면 std::optional을 사용할 수 있습니다:
std::optional<QMessageAuthenticationCode> mac;
~~~
key = ~~~;
mac.emplace(method, key);
use(*mac);참고: Qt 6.6 이전버전에서는 이 함수가 인자로 QByteArrayView 가 아닌 QByteArray 를 받았습니다. 컴파일 오류가 발생한다면, 이는 코드가 QByteArray 로 암시적으로 변환될 수 있지만 QByteArrayView 로는 변환될 수 없는 객체를 전달하고 있기 때문입니다. 해당 인자를 QByteArray{~~~} 로 감싸서 형 변환을 명시적으로 지정하십시오. 이는 이전 Qt 버전과 역호환됩니다.
[noexcept, since 6.6] void QMessageAuthenticationCode::swap(QMessageAuthenticationCode &other)
이 메시지 인증 코드를 ` other`로 교체합니다. 이 작업은 매우 빠르며 절대 실패하지 않습니다.
이 함수는 Qt 6.6에서 도입되었습니다.
[noexcept, since 6.6] QMessageAuthenticationCode &QMessageAuthenticationCode::operator=(QMessageAuthenticationCode &&other)
other 를 이 QMessageAuthenticationCode 인스턴스에 할당합니다.
참고: 이동된원본 객체 other 는 부분적으로 형성된 상태가 되며, 이 상태에서는 소멸 및 새 객체의 할당만이 유효한 연산입니다.
이 함수는 Qt 6.6에서 도입되었습니다.
© 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.