16 #if PLATFORM_CRYPTOGRAPHY && defined(_WIN32)
17 if (!CryptAcquireContext(&
m_Aes,
nullptr,
nullptr, PROV_RSA_AES, CRYPT_VERIFYCONTEXT))
19 throw std::system_error(GetLastError(), std::system_category());
22 mbedtls_aes_init(&
m_Aes);
33 #if PLATFORM_CRYPTOGRAPHY && defined(_WIN32)
34 CryptReleaseContext(
m_Aes, 0);
36 mbedtls_aes_free(&
m_Aes);
48 #if PLATFORM_CRYPTOGRAPHY && defined(_WIN32)
51 PUBLICKEYSTRUC Header;
56 const DWORD
Mode = CRYPT_MODE_CFB;
57 Key.Header = { PLAINTEXTKEYBLOB, CUR_BLOB_VERSION, 0, CALG_AES_128 };
59 std::copy_n(a_Key, 16, Key.Key);
61 CryptImportKey(
m_Aes,
reinterpret_cast<const BYTE *
>(&Key),
sizeof(Key), 0, 0, &m_Key);
62 CryptSetKeyParam(m_Key, KP_MODE,
reinterpret_cast<const BYTE *
>(&
Mode), 0);
63 CryptSetKeyParam(m_Key, KP_IV, a_IV, 0);
65 std::copy_n(a_IV, 16,
m_IV);
66 mbedtls_aes_setkey_enc(&
m_Aes, a_Key, 128);
80 #if PLATFORM_CRYPTOGRAPHY && defined(_WIN32)
81 ASSERT(a_Length <= std::numeric_limits<DWORD>::max());
83 DWORD Length =
static_cast<DWORD
>(a_Length);
84 CryptDecrypt(m_Key, 0, FALSE, 0,
reinterpret_cast<BYTE *
>(a_EncryptedIn), &Length);
86 mbedtls_aes_crypt_cfb8(&
m_Aes, MBEDTLS_AES_DECRYPT, a_Length,
m_IV,
reinterpret_cast<unsigned char *
>(a_EncryptedIn),
reinterpret_cast<unsigned char *
>(a_EncryptedIn));
Byte m_IV[16]
The InitialVector, used by the CFB mode decryption.
cAesCfb128Decryptor(void)
bool IsValid(void) const
Returns true if the object has been initialized with the Key / IV.
bool m_IsValid
Indicates whether the object has been initialized with the Key / IV.
void Init(const Byte a_Key[16], const Byte a_IV[16])
Initializes the decryptor with the specified Key / IV.
mbedtls_aes_context m_Aes
void ProcessData(std::byte *a_EncryptedIn, size_t a_Length)
Decrypts a_Length bytes of the encrypted data in-place; produces a_Length output bytes.