Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

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(hash_type: HashType, key: PackedByteArray)

Error

update(data: PackedByteArray)


方法說明

PackedByteArray finish() 🔗

返回生成的 HMAC。如果該 HMAC 失敗,則返回一個空的 PackedByteArray


Error start(hash_type: HashType, key: PackedByteArray) 🔗

初始化 HMACContext。在 finish() 被呼叫之前,不能在同一個 HMACContext 上再次呼叫此方法。


Error update(data: PackedByteArray) 🔗

更新要進行 HMAC 處理的消息。在 finish() 被呼叫以將 data 追加到該消息之前,該函式可以多次被呼叫,但在 start() 被呼叫之前不能被呼叫。