Files
UnrealEngineUWP/Engine/Source/Runtime/RSA/Private/RSA.cpp
ryan durand 0f0464a30e Updating copyright for Engine Runtime.
#rnx
#rb none


#ROBOMERGE-OWNER: ryan.durand
#ROBOMERGE-AUTHOR: ryan.durand
#ROBOMERGE-SOURCE: CL 10869210 via CL 10869511 via CL 10869900
#ROBOMERGE-BOT: (v613-10869866)

[CL 10870549 by ryan durand in Main branch]
2019-12-26 14:45:42 -05:00

94 lines
2.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "RSA.h"
#include "Features/IModularFeatures.h"
#include "Modules/ModuleManager.h"
static FCriticalSection GLock;
IEngineCrypto* GetEngineCrypto()
{
static TArray<IEngineCrypto*> Features = IModularFeatures::Get().GetModularFeatureImplementations<IEngineCrypto>(IEngineCrypto::GetFeatureName());
checkf(Features.Num() > 0, TEXT("RSA functionality was used but no modular feature was registered to provide it. Please make sure your project has the PlatformCrypto plugin enabled!"));
return Features[0];
}
FRSAKeyHandle FRSA::CreateKey(const TArray<uint8>& InPublicExponent, const TArray<uint8>& InPrivateExponent, const TArray<uint8>& InModulus)
{
if (IEngineCrypto* EngineCrypto = GetEngineCrypto())
{
return EngineCrypto->CreateRSAKey(InPublicExponent, InPrivateExponent, InModulus);
}
return nullptr;
}
void FRSA::DestroyKey(const FRSAKeyHandle InKey)
{
if (IEngineCrypto* EngineCrypto = GetEngineCrypto())
{
EngineCrypto->DestroyRSAKey(InKey);
}
}
int32 FRSA::GetKeySize(const FRSAKeyHandle InKey)
{
if (IEngineCrypto* EngineCrypto = GetEngineCrypto())
{
return EngineCrypto->GetKeySize(InKey);
}
return 0;
}
int32 FRSA::GetMaxDataSize(const FRSAKeyHandle InKey)
{
if (IEngineCrypto* EngineCrypto = GetEngineCrypto())
{
return EngineCrypto->GetMaxDataSize(InKey);
}
return 0;
}
int32 FRSA::EncryptPublic(const TArrayView<const uint8> InSource, TArray<uint8>& OutDestination, const FRSAKeyHandle InKey)
{
if (IEngineCrypto* EngineCrypto = GetEngineCrypto())
{
return EngineCrypto->EncryptPublic(InSource, OutDestination, InKey);
}
return -1;
}
int32 FRSA::EncryptPrivate(const TArrayView<const uint8> InSource, TArray<uint8>& OutDestination, const FRSAKeyHandle InKey)
{
if (IEngineCrypto* EngineCrypto = GetEngineCrypto())
{
return EngineCrypto->EncryptPrivate(InSource, OutDestination, InKey);
}
return -1;
}
int32 FRSA::DecryptPublic(const TArrayView<const uint8> InSource, TArray<uint8>& OutDestination, const FRSAKeyHandle InKey)
{
if (IEngineCrypto* EngineCrypto = GetEngineCrypto())
{
return EngineCrypto->DecryptPublic(InSource, OutDestination, InKey);
}
return -1;
}
int32 FRSA::DecryptPrivate(const TArrayView<const uint8> InSource, TArray<uint8>& OutDestination, const FRSAKeyHandle InKey)
{
if (IEngineCrypto* EngineCrypto = GetEngineCrypto())
{
return EngineCrypto->DecryptPrivate(InSource, OutDestination, InKey);
}
return -1;
}
IMPLEMENT_MODULE(FDefaultModuleImpl, RSA);