public ArrayList decrypt(byte[] encryptedData, int length) { ArrayList response = new ArrayList(); UInt16 pss = 0; UInt16 cseq = 0; UInt16 sseq = 0; PacketReader readerEncrypted = new PacketReader(encryptedData); readerEncrypted.incrementOffsetByValue(1); // skip 0x01 IV = readerEncrypted.readBytes(16); tf.setIV(IV); // Read the whole Data innerBuffer = new byte[encryptedData.Length - 17]; byte[] decryptBuffer = readerEncrypted.readBytes(encryptedData.Length - 17); tf.decrypt(decryptBuffer, innerBuffer); // just copy to clean byte[] decryptedPacket = innerBuffer; innerBuffer = new byte[2048]; PacketReader reader = new PacketReader(decryptedPacket); UInt32 crc32fromPacket = reader.readUInt32(1); byte[] packetCheckData = reader.readBytes(decryptedPacket.Length - 4); UInt32 crc32plainDataToCompare = NumericalUtils.ByteArrayToUint32(crc32.checksumB(packetCheckData, 1), 1); if (crc32plainDataToCompare != crc32fromPacket) { Output.WriteLine("Oh oh, CRC didnt matched in this packet"); } // as we read the whole packet for verifiy we reset the offset to read the other things reader.setOffsetOverrideValue(4); UInt16 packetSize = reader.readUInt16(1); // UInt32 timeStamp = reader.readUInt32(1); // Well we didnt need it - but just read it as uint32 UInt32 seqValues = reader.readUInt32(0); cseq = (UInt16)(seqValues & 0xFFF); sseq = (UInt16)(seqValues >> 12 & 0xFFF); pss = (UInt16)(seqValues >> 24 & 0xFF); // Finally add our responses and read the rest of the packet response.Add(reader.readBytes(packetSize - 4)); response.Add(pss); response.Add(cseq); response.Add(sseq); return(response); }
public byte[] decryptMargin(byte[] packet) { ArrayUtils.copy(packet, 1, IV, 0, 16); int decryptBuffer = packet.Length - 17; byte[] packetToDecrypt = new byte[decryptBuffer]; ArrayUtils.copy(packet, 17, packetToDecrypt, 0, packet.Length - 17); tf.setIV(IV); tf.setKey(TF_Key); byte[] decryptedBytes = new byte[packetToDecrypt.Length]; tf.decrypt(packetToDecrypt, decryptedBytes); byte[] decryptedPacket = new byte[decryptedBytes.Length - 10]; ArrayUtils.copy(decryptedBytes, 10, decryptedPacket, 0, decryptedBytes.Length - 10); return(decryptedPacket); }
private int twofishDecrypt() { 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[] cipherText = { 0x77, 0x7f, 0x54, 0xc6, 0xc9, 0x9e, 0x35, 0x56, 0x26, 0x4b, 0xc0, 0x17, 0x96, 0x33, 0x79, 0xe8 }; byte[] knownResult = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; byte[] result = new byte[16]; MxoTwofish tf = new MxoTwofish(); tf.setIV(iv); tf.setKey(key); tf.decrypt(cipherText, result); if (!ArrayUtils.equal(knownResult, result)) { Output.Write("Failed\n"); return(0); } Output.Write("OK\n"); return(1); }
public byte[] decryptMargin(byte[] packet) { if (packet.Length < 17) { // This happens - but shouldnt happen. return(null); } ArrayUtils.copy(packet, 1, IV, 0, 16); int decryptBuffer = packet.Length - 17; byte[] packetToDecrypt = new byte[decryptBuffer]; ArrayUtils.copy(packet, 17, packetToDecrypt, 0, packet.Length - 17); tf.setIV(IV); tf.setKey(TF_Key); byte[] decryptedBytes = new byte[packetToDecrypt.Length]; tf.decrypt(packetToDecrypt, decryptedBytes); byte[] decryptedPacket; if (decryptedBytes.Length > 10) { decryptedPacket = new byte[decryptedBytes.Length - 10]; } else { decryptedPacket = new byte[decryptedBytes.Length]; } ArrayUtils.copy(decryptedBytes, 10, decryptedPacket, 0, decryptedBytes.Length - 10); return(decryptedPacket); }
private int twofishDecrypt() { 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[] cipherText = {0x77,0x7f,0x54,0xc6,0xc9,0x9e,0x35,0x56,0x26,0x4b,0xc0,0x17,0x96,0x33,0x79,0xe8}; byte[] knownResult = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, 0x08 ,0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}; byte[] result = new byte[16]; MxoTwofish tf = new MxoTwofish(); tf.setIV(iv); tf.setKey(key); tf.decrypt(cipherText,result); if (!ArrayUtils.equal(knownResult, result)){ Output.Write("Failed\n"); return 0; } Output.Write("OK\n"); return 1; }