I tried with this code but the result is not as expected, maybe I am wrong somewhere, please help.
gcrypt.vapi from: https://gitlab.gnome.org/GNOME/vala-extra-vapis
using GCrypt;
using Posix;
void main () {
GCrypt.Cipher.Cipher cipher;
GCrypt.Error err = GCrypt.Cipher.Cipher.open(out cipher, Cipher.Algorithm.AES128, Cipher.Mode.CBC, Cipher.Flag.SECURE);
if (err != 0) {
print("Error: %s\n", err.to_string());
Process.exit(EXIT_FAILURE);
}
string iv = "1111111111111111";
string key = "2222222222222222";
err = cipher.set_key(key.data);
if (err != 0) {
print("Error key: %s\n", err.to_string());
Process.exit(EXIT_FAILURE);
}
err = cipher.set_iv(iv.data);
if (err != 0) {
print("Error iv: %s\n", err.to_string());
Process.exit(EXIT_FAILURE);
}
string str = "Hello World!!!!!";
uchar[] ary = new uchar[str.length];
print("ary: %d\n", ary.length);
err = cipher.encrypt(ary, str.data);
if (err != 0) {
print("Error encrypt: %s\n", err.to_string());
Process.exit(EXIT_FAILURE);
}
string result = Base64.encode(ary);
print("ary: %d\n", ary.length);
print("result: %s\n", result); // tus0150r+OSFg63kxluXpg==
// expect result: tus0150r+OSFg63kxluXpmlrUQOsLMbbgx51GhLZats=
cipher.close();
Process.exit(EXIT_SUCCESS);
}