German English

Encryption and Decryption of data with AES-ECB

An encrypted data transmission in wireless communication is of particular importance. Encryption prevents from unauthorized listening on the radio channel. A good encryption method is the Advanced Encryption Standard (AES) which is freely available and may be used without licensing fees. The transceiver on radio module Preon32 contains a hardware AES implementation for fast AES encryption and decryption.
This examples shows how to encrypt and decrypt 4 blocks of data, 16 bytes each, using the AES-ECB method.
 * Copyright (c) 2011., Virtenio GmbH
 * All rights reserved.

package com.virtenio.webdemo;

import com.virtenio.drivers.ieee_802_15_4.AT86RF231;
import com.virtenio.drivers.ieee_802_15_4.NativeAT86RF231;


public class RadioAESECB {

    public static void main(String[] args) throws IOException {

        NativeAT86RF231 t = NativeAT86RF231.getInstance(0);;

        byte[] key = {
                0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00,
                0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00

        byte[] data = new byte[]{
                0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
                0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F

        // AES-ECB Encryption/Decryption with byte-array
            byte[] data_encrypted = new byte[data.length];
            byte[] decryptKey = new byte[16];

            // Set Key
            t.aesEncryptECB(data, 0, data_encrypted, 0, 16);

            byte[] data_decrypted = new byte[data.length];

            t.aesDecryptECB(data_encrypted, 0, data_decrypted, 0, 16);