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.
Checking the stable version of the documentation...
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())
using Godot;
using System.Diagnostics;
public partial class MyNode : Node
{
private HmacContext _ctx = new HmacContext();
public override void _Ready()
{
byte[] key = "supersecret".ToUtf8Buffer();
Error err = _ctx.Start(HashingContext.HashType.Sha256, key);
Debug.Assert(err == Error.Ok);
byte[] msg1 = "this is ".ToUtf8Buffer();
byte[] msg2 = "super duper secret".ToUtf8Buffer();
err = _ctx.Update(msg1);
Debug.Assert(err == Error.Ok);
err = _ctx.Update(msg2);
Debug.Assert(err == Error.Ok);
byte[] hmac = _ctx.Finish();
GD.Print(hmac.HexEncode());
}
}
方法
finish() |
|
start(hash_type: HashType, key: PackedByteArray) |
|
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() 被调用之前不能被调用。