Encrypt and Decrypt using AES

I am trying to get basic string encryption and decryption exposed to my blueprints. And was wondering if I am doing it right. I currently have this:

FString UCustomExtensions::Encrypt(FString data, FString key) {

	if (data.IsEmpty() || key.IsEmpty()) {
		return "";
	}

	FBufferArchive binArchive;
	binArchive << data;

	int32 size = binArchive.Num();
	uint8* encrypted = new uint8[size];
	FMemory::Memcpy(encrypted, binArchive.GetData(), size);

	const TCHAR* charkey = key.GetCharArray().GetData();
	FAES::EncryptData(encrypted, size, TCHAR_TO_ANSI(charkey));

	TArray<uint8> encryptedArray;
	encryptedArray.Append(encrypted, size);
	FString ret = FString::FromHexBlob(encrypted,size);
	delete encrypted;

	return ret;
}

as encryption. It seems to produce consistent result. I am curious how could one decrypt this string? In particular the problem I am having is getting this string converted back into binary blob for further decryption.

Any help is appreciated.

Did you find a solution for this? I am also interested.

@JavierRamello, yes, kind of. I’ve packaged libsodium as UE4 plugin. You can check it out here:

Only public, and authenticated public functionality is exposed to blueprint right now. Only tested on windows.

An AES Plugin: