Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

HMACContext

继承: RefCounted < Object

用来为一个使用密钥的信息创建 HMAC。

描述

HMACContext 类对于高级的 HMAC 用例非常有用,例如流式消息,因为它支持在一段时间内创建消息,而非一次性提供。

extends Node
var ctx = HMACContext.new()

func _ready():
    var key = "supersecret".to_utf8_buffer()
    var err = ctx.start(HashingContext.HASH_SHA256, key)
    assert(err == OK)
    var msg1 = "this is ".to_utf8_buffer()
    var msg2 = "super duper secret".to_utf8_buffer()
    err = ctx.update(msg1)
    assert(err == OK)
    err = ctx.update(msg2)
    assert(err == OK)
    var hmac = ctx.finish()
    print(hmac.hex_encode())

方法

PackedByteArray

finish ( )

Error

start ( HashType hash_type, PackedByteArray key )

Error

update ( PackedByteArray data )


方法说明

PackedByteArray finish ( )

返回生成的 HMAC。如果该 HMAC 失败,则返回一个空的 PackedByteArray


Error start ( HashType hash_type, PackedByteArray key )

初始化 HMACContext。在 finish 被调用之前,不能在同一个 HMACContext 上再次调用此方法。


Error update ( PackedByteArray data )

更新要进行 HMAC 处理的消息。在 finish 被调用以将 data 追加到该消息之前,该函数可以多次被调用,但在 start 被调用之前不能被调用。