I can't encrypt and load my external .pak at runtime

Hi,

I have fallowed this tutorial in order to create and load an external .pak at runtime for my game:

It works.
But know i want to encrypt my external .pak and load it in my game.
How can i do that ?
I haven’t found any clear documentation about that.

To encrypt my .pak i have tried to use this documentation:

In project settings of the project used to create my .pak, i have juste:
_ Generated EncryptionKey
_ Checked: “Encrypt Pak ini Files”
_ Checked: “Encrypt Pak Index”

If i package the project, the generated .pak cannot be loaded anymore by my game. I have this error:
Fatal error: [File:D:\build++UE5\Sync\Engine\Source\Runtime\PakFile\Private\IPlatformFilePak.cpp] [Line: 349]
Failed to find requested encryption key 00000000000000000000000000000000

I have tried to had:
PublicDefinitions.Add(“AES_KEY=oIq0YO3Ow1YsMCc0MT1meGVFYeRA5vO9sbPQKhet+Zo=”);
in MyGamePakLoader.Build.cs
it doesn’t work.

Is my .pak correctly encrypted ?
Where and how can i set the EncryptionKey in my game to load the .pak ?

Problem solved:

FKeyChain keyChain;
FString EncryptionKeyBase64 = “oIq0YO3Ow1YsMCc0MT1meGVFYeRA5vO9sbPQKhet+Zo=”; // MyKey
TArray Key;
FBase64::Decode(EncryptionKeyBase64, Key);
check(Key.Num() == sizeof(FAES::FAESKey::Key));
FNamedAESKey NewKey;
NewKey.Name = TEXT(“Default”);
NewKey.Guid = FGuid();
FMemory::Memcpy(NewKey.Key.Key, &Key[0], sizeof(FAES::FAESKey::Key));
keyChain.GetEncryptionKeys().Add(NewKey.Guid, NewKey);
KeyChainUtilities::ApplyEncryptionKeys(keyChain);

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.