Class Hmac
- All Implemented Interfaces:
Proxy
Both the key and data are arbitrary byte arrays of bytes or characters.
Support for HMAC Digests has been added in GLib 2.30, and support for SHA-512 in GLib 2.42. Support for SHA-384 was added in GLib 2.52.
To create a new GHmac
, use Hmac(org.gnome.glib.ChecksumType, byte[])
. To free a GHmac
, use
unref()
.
-
Constructor Summary
ConstructorDescriptionHmac
(MemorySegment address) Create a Hmac proxy instance for the provided memory address.Hmac
(ChecksumType digestType, byte[] key) Creates a newGHmac
, using the digest algorithmdigestType
. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Copies aGHmac
.void
getDigest
(byte[] buffer) Gets the digest fromchecksum
as a raw binary array and places it intobuffer
.Gets the HMAC as a hexadecimal string.static Type
getType()
Get the GType of the Hmac classref()
Atomically increments the reference count of this Hmac by one.void
unref()
Atomically decrements the reference count of this Hmac by one.void
update
(byte[] data) Feedsdata
into an existingGHmac
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Hmac
Create a Hmac proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Hmac
Creates a newGHmac
, using the digest algorithmdigestType
. If thedigestType
is not known,null
is returned. AGHmac
can be used to compute the HMAC of a key and an arbitrary binary blob, using different hashing algorithms.A
GHmac
works by feeding a binary blob through g_hmac_update() until the data is complete; the digest can then be extracted using g_hmac_get_string(), which will return the checksum as a hexadecimal string; or g_hmac_get_digest(), which will return a array of raw bytes. Once either g_hmac_get_string() or g_hmac_get_digest() have been called on aGHmac
, the HMAC will be closed and it won't be possible to call g_hmac_update() on it anymore.Support for digests of type
ChecksumType.SHA512
has been added in GLib 2.42. Support forChecksumType.SHA384
was added in GLib 2.52.- Parameters:
digestType
- the desired type of digestkey
- the key for the HMAC
-
-
Method Details
-
getType
-
copy
Copies aGHmac
. If this Hmac has been closed, by calling g_hmac_get_string() or g_hmac_get_digest(), the copied HMAC will be closed as well.- Returns:
- the copy of the passed
GHmac
. Use g_hmac_unref() when finished using it.
-
getDigest
public void getDigest(byte[] buffer) Gets the digest fromchecksum
as a raw binary array and places it intobuffer
. The size of the digest depends on the type of checksum.Once this function has been called, the
GHmac
is closed and can no longer be updated with g_checksum_update().- Parameters:
buffer
- output buffer
-
getString
Gets the HMAC as a hexadecimal string.Once this function has been called the
GHmac
can no longer be updated with g_hmac_update().The hexadecimal characters will be lower case.
- Returns:
- the hexadecimal representation of the HMAC. The returned string is owned by the HMAC and should not be modified or freed.
-
ref
Atomically increments the reference count of this Hmac by one.This function is MT-safe and may be called from any thread.
- Returns:
- the passed in
GHmac
.
-
unref
public void unref()Atomically decrements the reference count of this Hmac by one.If the reference count drops to 0, all keys and values will be destroyed, and all memory allocated by the hash table is released. This function is MT-safe and may be called from any thread. Frees the memory allocated for this Hmac.
-
update
public void update(byte[] data) Feedsdata
into an existingGHmac
.The HMAC must still be open, that is g_hmac_get_string() or g_hmac_get_digest() must not have been called on this Hmac.
- Parameters:
data
- buffer used to compute the checksum
-