This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How do I encrypt a string?

Hello.
We are developing using nrf52832 (S132 v7.0.1, SDK v17.0.0).

I'm looking at how to encrypt a string with AES CBC.
Below is the code we are considering.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static uint8_t m_key[16] = {'N', 'O', 'R', 'D', 'I', 'C', 'A', 'E', 'S', 'C', 'B', 'C', 'T', 'E', 'S', 'T'};
static char m_plain_text[NRF_CRYPTO_EXAMPLE_AES_MAX_TEXT_SIZE] =
{
"Example string to demonstrate basic usage of AES CBC mode."
};
static char m_encrypted_text[NRF_CRYPTO_EXAMPLE_AES_MAX_TEXT_SIZE];
static void crypto_test(void){
static nrf_crypto_aes_context_t cbc_encr_ctx;
static nrf_crypto_aes_context_t cbc_decr_ctx;
ret_code_t ret_val;
uint8_t iv[NRF_CRYPTO_MBEDTLS_AES_IV_SIZE]; // 16
size_t len_in;
size_t len_out;
memset(m_encrypted_text, 0, sizeof(m_encrypted_text));
memset(m_decrypted_text, 0, sizeof(m_decrypted_text));
memset(iv, 0, sizeof(iv));
len_in = strlen(m_plain_text);
len_out = sizeof(m_encrypted_text);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Currently, it works, but the strings are not encrypted and are all "0x00".
How can I solve it?

Best Regards.