compute_for_string


Description:

[ CCode ( cname = "g_compute_checksum_for_string" ) ]
public static string compute_for_string (ChecksumType checksum_type, string str, size_t length = -1)

Computes the checksum of a string.

The hexadecimal string returned will be in lower case.

Example: Compute the checksum of a string (convenience function):

public static int main (string[] args) {
string password = "123supersecret";
string salt = "dummy-salt";

// md5 (password) = 2137ac274355e2e180d5125ae28fc408
string hash = GLib.Checksum.compute_for_string (ChecksumType.MD5, password, password.length);

// md5 (md5 (password) + salt) = ce48e145cb9fdcaf6ba2f63afc262d14
hash = GLib.Checksum.compute_for_string (ChecksumType.MD5, hash + salt);
print ("Hash: %s\n", hash);
return 0;
}

valac --pkg glib-2.0 GLib.Checksum.compute_for_string.vala

Parameters:

checksum_type

a ChecksumType

str

the string to compute the checksum of

length

the length of the string, or -1 if the string is null-terminated.

Returns:

the checksum as a hexadecimal string. The returned string should be freed with g_free when done using it.