private int twofishEncrypt() { ArrayUtils au = new ArrayUtils(); byte[] key = { 0xa4, 0x46, 0xdc, 0x73, 0x25, 0x08, 0xee, 0xb7, 0x6c, 0x9e, 0xb4, 0x4a, 0xb8, 0xe7, 0x11, 0x03 }; byte[] iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; byte[] plainText = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; byte[] knownResult = { 0xba, 0x05, 0xf5, 0x6e, 0x86, 0x5f, 0xb6, 0xc9, 0xb2, 0x1d, 0xe1, 0x00, 0xb6, 0xec, 0x46, 0xe9 }; byte[] result = new byte[16]; MxoTwofish tf = new MxoTwofish(); tf.setIV(iv); tf.setKey(key); tf.encrypt(plainText, result); if (!ArrayUtils.equal(knownResult, result)) { Output.Write("Failed\n"); Output.WriteLine(StringUtils.bytesToString(knownResult)); Output.WriteLine(StringUtils.bytesToString(result)); return(0); } Output.Write("OK\n"); return(1); }
private int twofishEncrypt() { ArrayUtils au = new ArrayUtils(); byte[] key = { 0xa4,0x46,0xdc,0x73,0x25,0x08,0xee,0xb7,0x6c,0x9e,0xb4,0x4a,0xb8,0xe7,0x11,0x03 }; byte[] iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; byte[] plainText = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; byte[] knownResult = {0xba,0x05,0xf5,0x6e,0x86,0x5f,0xb6,0xc9,0xb2,0x1d,0xe1,0x00,0xb6,0xec,0x46,0xe9}; byte[] result = new byte[16]; MxoTwofish tf = new MxoTwofish(); tf.setIV(iv); tf.setKey(key); tf.encrypt(plainText,result); if (!ArrayUtils.equal(knownResult, result)){ Output.Write("Failed\n"); Output.WriteLine(StringUtils.bytesToString(knownResult)); Output.WriteLine(StringUtils.bytesToString(result)); return 0; } Output.Write("OK\n"); return 1; }
public byte[] encrypt(byte[] plainData, int length, ushort pss, ushort cseq, ushort sseq) { UInt32 seqValue = (uint)pss << 24 | (uint)cseq << 12 | (uint)sseq; byte[] sequences = BitConverter.GetBytes(seqValue); Array.Reverse(sequences); // Create the packet that needs to be CRC32 checksummed PacketContent packet = new PacketContent(); packet.addUint16((UInt16)(plainData.Length + 4), 1); packet.addByteArray(TimeUtils.getCurrentTime()); packet.addByteArray(sequences); packet.addByteArray(plainData); byte[] paddingBytes = getPaddedBytes(packet.returnFinalPacket()); // Final Packet which needs to be encrypted PacketContent packetWithCrc = new PacketContent(); packetWithCrc.addByteArray(crc32.checksumB(packet.returnFinalPacket(), 1)); packetWithCrc.addByteArray(packet.returnFinalPacket()); packetWithCrc.addByteArray(paddingBytes); string hexPackCrcedPlain = StringUtils.bytesToString(packetWithCrc.returnFinalPacket()); string paddingBytesHex = StringUtils.bytesToString(paddingBytes); innerBuffer = new byte[packetWithCrc.returnFinalPacket().Length]; tf.encrypt(packetWithCrc.returnFinalPacket(), innerBuffer); PacketContent encryptedPacket = new PacketContent(); encryptedPacket.addByte(0x01); encryptedPacket.addByteArray(IV); encryptedPacket.addByteArray(innerBuffer); innerBuffer = new byte [2048]; string hexPackEncrypt = StringUtils.bytesToString(encryptedPacket.returnFinalPacket()); return(encryptedPacket.returnFinalPacket()); }
private int twofishEncrypt() { byte[] key = { 0x6C, 0xAB, 0x8E, 0xCC, 0xE7, 0x3C, 0x22, 0x47, 0xDB, 0xEB, 0xDE, 0x1A, 0xA8, 0xE7, 0x5F, 0xB8 }; byte[] iv = { 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30 }; byte[] plainText = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; byte[] knownResult = { 0x77, 0x7f, 0x54, 0xc6, 0xc9, 0x9e, 0x35, 0x56, 0x26, 0x4b, 0xc0, 0x17, 0x96, 0x33, 0x79, 0xe8 }; byte[] result = new byte[16]; MxoTwofish tf = new MxoTwofish(); tf.setIV(iv); tf.setKey(key); tf.encrypt(plainText, result); if (!ArrayUtils.equal(knownResult, result)) { Output.Write("Failed\n"); Output.WriteLine(StringUtils.bytesToString(knownResult)); Output.WriteLine(StringUtils.bytesToString(result)); return(0); } Output.Write("OK\n"); return(1); }
public byte[] encrypt(byte[] packet) { // Get timestamp byte[] timestamp = TimeUtils.getUnixTime(); // get size int psize = packet.Length; byte[] size = NumericalUtils.uint16ToByteArray((UInt16)psize, 1); //showPacket(size, " Size "); // final Packet DynamicArray temp = new DynamicArray(); temp.append(size); temp.append(timestamp); temp.append(packet); // compute CRC32 byte[] crc32pax = crc32.checksumB(temp.getBytes(), 1); // Padding int totalLength = temp.getSize() + 4; int padding = 16 - (totalLength % 16); byte[] paddingBytes = new byte[padding]; for (int i = 0; i < padding; i++) { paddingBytes[i] = (byte)padding; } temp.append(paddingBytes); tf.setIV(IV); tf.setKey(TF_Key); // We init with 2 more than needed, so no memory reservation is done on dyn array DynamicArray finalPlainData = new DynamicArray(); finalPlainData.append(crc32pax); finalPlainData.append(temp.getBytes()); temp = null; // Cleaning the house byte[] encryptedData = new byte[finalPlainData.getSize()]; tf.encrypt(finalPlainData.getBytes(), encryptedData); finalPlainData = null; // Cleaning the house (2) // add IV before the results DynamicArray response = new DynamicArray(); response.append(IV); response.append(encryptedData); // Display HEX Values after Encryption return(response.getBytes()); }
private int twofishEncrypt() { byte[] key = { 0x6C, 0xAB, 0x8E, 0xCC, 0xE7, 0x3C, 0x22, 0x47, 0xDB, 0xEB, 0xDE, 0x1A, 0xA8, 0xE7, 0x5F, 0xB8 }; byte[] iv = { 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30 }; byte[] plainText = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, 0x08 ,0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; byte[] knownResult = {0x77,0x7f,0x54,0xc6,0xc9,0x9e,0x35,0x56,0x26,0x4b,0xc0,0x17,0x96,0x33,0x79,0xe8}; byte[] result = new byte[16]; MxoTwofish tf = new MxoTwofish(); tf.setIV(iv); tf.setKey(key); tf.encrypt(plainText,result); if (!ArrayUtils.equal(knownResult, result)) { Output.Write("Failed\n"); Output.WriteLine(StringUtils.bytesToString(knownResult)); Output.WriteLine(StringUtils.bytesToString(result)); return 0; } Output.Write("OK\n"); return 1; }