Encrypt / Decrypt data using blueprints (or C++)

Hi folks,

I’m looking for a way to encrypt data before sending it to our database server and to decrypt a response or result gotten from the same server.

Currently I’m transmitting information using the JSON Query Plugin, which is plain text in sending and receiving anything. Obviously this can be manipulated rather easily (once you figured out some minor hurdles).

I’ve found another thread mentioning the FAES::EncryptData and FAES::DecryptData functions within the engines code, but they don’t seem to be ready or accessible yet? The questioner was using 4.2 back when he asked for a solution - now we’re up to 4.7 and I didn’t see a change when looking at the code.

I’m not that used to C++ at the moment, so I’m looking for a blueprint way to utilize the en-/decryption functions. A small C++ helper plugin would be fully ok too, if thats the best (only?) way to get the desired BP nodes ready for me and my mates.

Thanks for any hint or idea!

I would like to bump this, because I am also interested in security of some data, is there any way to use encryption/decryption in blueprints ? Or do I have to create a unique one myself ?

I’m interested in this as well!

Bumping my own question with a comment so it gets to the category overview again (at least thats how I guess it works).

Anything on this?

EPIC STAFF…

BUMPING ON THIS

bumping this

UP - for Encrypt / Decrypt data using blueprints

I have found this on Google, but for some reason when I try to decrypt return a empty string.

In .h:

UFUNCTION(BlueprintCallable, Category = "AES256")
static FString Encrypt(FString InputString, FString Key);

UFUNCTION(BlueprintCallable, Category = "AES256")
static FString Decrypt(FString InputString, FString Key);

In .cpp:

FString UChangeToYourBlueprintFunctionLibraryName::Encrypt(FString InputString, FString Key)
{
	// Check inputs
	if (InputString.IsEmpty()) return "";  //empty string? do nothing
	if (Key.IsEmpty()) return "";

	// To split correctly final result of decryption from trash symbols
	FString SplitSymbol = "EL@$@!";
	InputString.Append(SplitSymbol);

	// We need at least 32 symbols key
	Key = FMD5::HashAnsiString(*Key);
	TCHAR *KeyTChar = Key.GetCharArray().GetData();           
	ANSICHAR *KeyAnsi = (ANSICHAR*)TCHAR_TO_ANSI(KeyTChar);

	// Calculate blob size and create blob
	uint8* Blob; 
	uint32 Size; 
	 
	Size = InputString.Len();
	Size = Size + (FAES::AESBlockSize - (Size % FAES::AESBlockSize));

	Blob = new uint8[Size];

	// Convert string to bytes and encrypt
	if(StringToBytes(InputString, Blob, Size)) {

		FAES::EncryptData(Blob, Size, KeyAnsi);
		InputString = FString::FromHexBlob(Blob, Size);

		delete Blob;
		return InputString;		
	}

	delete Blob;
	return ""; 
}

FString UChangeToYourBlueprintFunctionLibraryName::Decrypt(FString InputString, FString Key)
{
	// Check inputs
	if (InputString.IsEmpty()) return ""; 
	if (Key.IsEmpty()) return "";

	// To split correctly final result of decryption from trash symbols
	FString SplitSymbol = "EL@$@!";

	// We need at least 32 symbols key
	Key = FMD5::HashAnsiString(*Key);
	TCHAR *KeyTChar = Key.GetCharArray().GetData();
	ANSICHAR *KeyAnsi = (ANSICHAR*)TCHAR_TO_ANSI(KeyTChar);
	
	// Calculate blob size and create blob
	uint8* Blob; 
	uint32 Size; 

	Size = InputString.Len();
	Size = Size + (FAES::AESBlockSize - (Size % FAES::AESBlockSize));

	Blob = new uint8[Size]; 

	// Convert string to bytes and decrypt
	if (FString::ToHexBlob(InputString, Blob, Size)) {

		FAES::DecryptData(Blob, Size, KeyAnsi);		
		InputString = BytesToString(Blob, Size);

		// Split required data from trash
		FString LeftData;	
		FString RightData;	
		InputString.Split(SplitSymbol, &LeftData, &RightData, ESearchCase::CaseSensitive, ESearchDir::FromStart);
		InputString = LeftData;

		delete Blob; 
		return InputString; 
	}

	delete Blob; 
	return ""; 
}

Also include in .cpp:

 #include "Runtime/Core/Public/Misc/AES.h"
 #include "Runtime/Core/Public/Misc/SecureHash.h"
#include "Runtime/Core/Public/Misc/Base64.h"
2 Likes