Gum Crypt

Gum Crypt — Utility functions for encryption

Synopsis

#include <gum/common/gum-crypt.h>

gint                gum_crypt_cmp_secret                (const gchar *plain_str1,
                                                         const gchar *enc_str2);
gchar *             gum_crypt_encrypt_secret            (const gchar *secret,
                                                         const gchar *encryp_algo);

Description

Following code snippets shows how a string can be encrypted with any of the supported encryption algorithm. Moreover, plain and encrypted secrets can be compared if needed.

  gchar *pass = gum_crypt_encrypt_secret("pas.-s123", "SHA512");
  g_free (pass);

  pass = gum_crypt_encrypt_secret("pass ?()123", "SHA512");
  gum_crypt_cmp_secret("pass ?()123", pass); //should return true.
  g_free (pass);

Details

gum_crypt_cmp_secret ()

gint                gum_crypt_cmp_secret                (const gchar *plain_str1,
                                                         const gchar *enc_str2);

Encrypts plain string with the same parameters as that of encrypted string and then compares both encrypted strings.

plain_str1 :

plain string. [transfer none]

enc_str2 :

encrypted string. [transfer none]

Returns :

0 if enc_str1 == enc_str2, less than 0 if the enc_str1 < enc_str2, greater than 0 if enc_str1 > enc_str2.

gum_crypt_encrypt_secret ()

gchar *             gum_crypt_encrypt_secret            (const gchar *secret,
                                                         const gchar *encryp_algo);

Encrypts the secret with the specified algorithm encryp_algo.

secret :

string to encrypt. [transfer none]

encryp_algo :

algorithm to be used for encryption. 'MD5', 'SHA256', 'SHA512', and 'DES' are supported algorithms.

Returns :

encrypted secret if successful, NULL otherwise. [transfer full]