HMACContext

继承: RefCounted < Object

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

描述

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

GDScriptC#

  1. extends Node
  2. var ctx = HMACContext.new()
  3. func _ready():
  4. var key = "supersecret".to_utf8_buffer()
  5. var err = ctx.start(HashingContext.HASH_SHA256, key)
  6. assert(err == OK)
  7. var msg1 = "this is ".to_utf8_buffer()
  8. var msg2 = "super duper secret".to_utf8_buffer()
  9. err = ctx.update(msg1)
  10. assert(err == OK)
  11. err = ctx.update(msg2)
  12. assert(err == OK)
  13. var hmac = ctx.finish()
  14. print(hmac.hex_encode())
  1. using Godot;
  2. using System.Diagnostics;
  3. public partial class MyNode : Node
  4. {
  5. private HmacContext _ctx = new HmacContext();
  6. public override void _Ready()
  7. {
  8. byte[] key = "supersecret".ToUtf8Buffer();
  9. Error err = _ctx.Start(HashingContext.HashType.Sha256, key);
  10. Debug.Assert(err == Error.Ok);
  11. byte[] msg1 = "this is ".ToUtf8Buffer();
  12. byte[] msg2 = "super duper secret".ToUtf8Buffer();
  13. err = _ctx.Update(msg1);
  14. Debug.Assert(err == Error.Ok);
  15. err = _ctx.Update(msg2);
  16. Debug.Assert(err == Error.Ok);
  17. byte[] hmac = _ctx.Finish();
  18. GD.Print(hmac.HexEncode());
  19. }
  20. }

方法

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 被调用之前不能被调用。

Previous Next


© 版权所有 2014-present Juan Linietsky, Ariel Manzur and the Godot community (CC BY 3.0). Revision b1c660f7.

Built with Sphinx using a theme provided by Read the Docs.