Hi
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? :\