Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

XTEA encryption on Netduino Plus 2

np2 xtea bouncy castle

  • Please log in to reply
No replies to this topic

#1 Kip

Kip

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationItaly

Posted 11 March 2014 - 11:29 AM

Hi :D

 

I'm trying to do some basic encryption on NP2 using XTEA.

I'm using the well-tested Bouncy Castle lib, so imported the necessary source files in my project:

 

  • CryptoException.cs
  • DataLengthException.cs
  • IBlockCipher.cs
  • ICipherParameters.cs
  • KeyParameter.cs
  • Pack.cs
  • XTEAEngine.cs

then I tried it, by encoding and decoding a block of 8 bytes, using this code:

byte[] keyData = Encoding.UTF8.GetBytes("passwordpassword");

byte[] plainData = Encoding.UTF8.GetBytes("xteaxtea");
XteaEngine xteaEngine = new XteaEngine();
xteaEngine.Init(true, new KeyParameter(keyData));

byte[] outData = new byte[plainData.Length];

xteaEngine.ProcessBlock(plainData, 0, outData, 0);

XteaEngine decEngine = new XteaEngine();
decEngine.Init(false, new KeyParameter(keyData));
byte[] decData = new byte[plainData.Length];
xteaEngine.ProcessBlock(outData, 0, decData, 0);

string str = new string(Encoding.UTF8.GetChars(decData));
Debug.Print(str);

but plainData != decData, even if they should have the same data! What am I doing wrong? :\







Also tagged with one or more of these keywords: np2, xtea, bouncy castle

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.