Excellent, library very quick and efficient however, there is an issue with the CBC decrypt, below is my code running on arduino
#include <Base64.h>
#include <AES.h>
AES aes ;
byte key[] =
{
12,13,14,15,15,16,17,18,19,10,11,12,13,14,15,16
,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32
} ;
byte my_iv[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
} ;
//byte cipher [4*N_BLOCK] ;
byte check [4*N_BLOCK] ;
void loop ()
{}
void setup ()
{
Serial.begin (57600) ;
delay(30000);
Serial.println("testing mode") ;
byte succ = aes.set_key (key, 256) ;
byte iv [N_BLOCK] ;
for (byte i = 0 ; i < 16 ; i++)
iv[i] = my_iv[i] ;
int decodedLen = 32;
byte decoded[] = {70,33,158,65,106,36,73,238,61,225,69,115,121,47,148,114,238,92,183,97,37,152,168,11,248,112,41,187,179,2,119,250};
succ = aes.cbc_decrypt (decoded, check, (decodedLen/N_BLOCK), iv) ;
aes.clean();
for(int i=0; i<decodedLen;i++)
{
Serial.print((char)check[i]);
}
Serial.println("");
}
This is decrypted but not correctly, the second block, first byte us incorrect, decrypted the string should read Decoded hello world encrypted!!! but this library decodes as Decoded hello wnrld encrypted!!!
The encrypted text is from a C# console app
using System;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sandbox
{
class Program
{
static void Main(string[] args)
{
var isLE = BitConverter.IsLittleEndian;
byte[] encrypData = System.Text.Encoding.UTF8.GetBytes("Decoded hello world encrypted!!!");
using (AesManaged crypto = new AesManaged())
{
crypto.IV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
crypto.Key = new byte[] {12,13,14,15,15,16,17,18,19,10,11,12,13,14,15,16
,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32};
crypto.Mode = CipherMode.CBC;
using (var encryptor = crypto.CreateEncryptor())
{
var outBuffer = new byte[32];
encryptor.TransformBlock(encrypData, 0, 32, outBuffer, 0);
}
}
}
}
}
Any ideas what could be causing the issue? I have checked from previous threads about endian and I can confirm both are little.