QMessageAuthenticationCode Class

QMessageAuthenticationCode 클래스는 해시 기반 메시지 인증 코드를 생성하는 방법을 제공합니다. 더 보기...

Header: #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)

상세 설명

해시 기반 메시지 인증 코드(HMAC)를 생성하려면 QMessageAuthenticationCode 클래스를 사용합니다. 이 클래스는 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의 암호화 강도는 비밀 키의 크기와 기본 해시 함수의 보안에 따라 달라집니다.

QCryptographicHashQCryptographicHash::Algorithm참조하세요 .

멤버 함수 문서

[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()도 참조하십시오 .

[explicit] QMessageAuthenticationCode::QMessageAuthenticationCode(QCryptographicHash::Algorithm method, QByteArrayView key = {})

메서드 method 와 키 key 를 사용하여 데이터에서 암호화 해시를 만드는 데 사용할 수 있는 객체를 구축합니다.

참고: 6.6 이전 Qt 버전에서 이 함수는 인자를 QByteArrayView 이 아닌 QByteArray 로 받습니다. 컴파일 에러가 발생하면 코드가 암시적으로 QByteArray 로 변환 가능한 객체를 전달하지만 QByteArrayView 으로 변환할 수 없는 객체를 전달하기 때문입니다. 해당 인수를 QByteArray{~~~} 로 감싸서 명시적으로 형변환을 하세요. 이것은 이전 Qt 버전과 역호환됩니다.

[noexcept, since 6.6] QMessageAuthenticationCode::QMessageAuthenticationCode(QMessageAuthenticationCode &&other)

Move는 other 에서 새 QMessageAuthenticationCode를 생성합니다.

참고: 이동한 객체 other 는 부분적으로 형성된 상태로 배치되며, 유효한 작업은 소멸과 새 객체 할당뿐입니다.

이 함수는 Qt 6.6에 도입되었습니다.

[noexcept] QMessageAuthenticationCode::~QMessageAuthenticationCode()

개체를 파괴합니다.

[noexcept] void QMessageAuthenticationCode::addData(QByteArrayView data)

메시지에 data 을 추가합니다.

참고: 6.6 이전 Qt 버전에서 이 함수는 인수를 QByteArrayView 이 아닌 QByteArray 으로 받습니다. 컴파일 오류가 발생하는 경우 코드가 QByteArray 로 암시적으로 변환 가능한 객체를 전달하지만 QByteArrayView 으로는 변환할 수 없는 객체를 전달하기 때문입니다. 해당 인수를 QByteArray{~~~} 로 감싸서 명시적으로 형변환을 하세요. 이 방법은 이전 Qt 버전과 역호환됩니다.

resultView() 및 result()도 참조하십시오 .

bool QMessageAuthenticationCode::addData(QIODevice *device)

열린 QIODevice device 에서 데이터가 끝날 때까지 데이터를 읽고 메시지에 추가합니다. 읽기에 성공하면 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 메시지에 대한 인증 코드를 반환합니다.

참고: 6.6 이전 Qt 버전에서 이 함수는 인자를 QByteArrayView 이 아닌 QByteArray 로 받습니다. 컴파일 오류가 발생하면 코드가 암시적으로 QByteArray 로 변환 가능한 객체를 전달하지만 QByteArrayView 으로 변환할 수 없는 객체를 전달하기 때문입니다. 해당 인수를 QByteArray{~~~} 로 감싸서 명시적으로 형변환을 하세요. 이 방법은 이전 Qt 버전과 역호환됩니다.

hashInto()도 참조하십시오 .

[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);

std::optional을 사용하여 키를 알 때까지 QMessageAuthenticationCode 구성을 지연시킬 수 있습니다:

std::optional<QMessageAuthenticationCode> mac;
~~~
key = ~~~;
mac.emplace(method, key);
use(*mac);

참고: 6.6 이전 Qt 버전에서, 이 함수는 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에 도입되었습니다.

© 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.