public static byte[] ScrambleDecrypt(byte[] scrambledData, KeyBlock key) { byte[] result = new byte[scrambledData.Length]; int keyPos = 0; int keyShift = 0; for (int i = 0; i < scrambledData.Length; ++i) { while (key[keyPos] >= ((scrambledData.Length - keyShift))) { keyPos++; if (keyPos >= key.KeyLength) { keyPos = 0; keyShift = i + 1; } } result[key[keyPos] + keyShift] = scrambledData[i]; keyPos++; if (keyPos >= key.KeyLength) { keyPos = 0; keyShift = i + 1; } } return(result); }
public void ChangeLocalState() { _outputCipherSuite = _nextCipherSuite; _outputKeyBlock = _nextKeyBlock; _outputSequenceNumber = 0; _outputEpoch++; if (_isClient) { _outputHasher = _outputCipherSuite.MACAlgorithm.CreateHasher(_outputKeyBlock.ClientWriteMACKey); _encryptor = _outputCipherSuite.BulkCipherAlgorithm.CreateEncryptor(_outputKeyBlock.ClientWriteKey, _outputKeyBlock.ClientWriteIV); _outputKey = _outputKeyBlock.ClientWriteKey; _outputFixedIV = _outputKeyBlock.ClientWriteIV; } else { _outputHasher = _outputCipherSuite.MACAlgorithm.CreateHasher(_outputKeyBlock.ServerWriteMACKey); _encryptor = _outputCipherSuite.BulkCipherAlgorithm.CreateEncryptor(_outputKeyBlock.ServerWriteKey, _outputKeyBlock.ServerWriteIV); _outputKey = _outputKeyBlock.ServerWriteKey; _outputFixedIV = _outputKeyBlock.ServerWriteIV; } // IMPORTANT: This needs to be XORed with ie. sequence number to make sure it is unique _outputRecordIV = new byte[_outputCipherSuite.BulkCipherAlgorithm.RecordIVLength]; RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider(); rngCsp.GetBytes(_outputRecordIV); }
public void ChangeRemoteState() { _inputCipherSuite = _nextCipherSuite; _inputKeyBlock = _nextKeyBlock; _inputSequenceNumber = 0; _inputEpoch++; if (_isClient) { _inputHasher = _inputCipherSuite.MACAlgorithm.CreateHasher(_inputKeyBlock.ServerWriteMACKey); _decryptor = _inputCipherSuite.BulkCipherAlgorithm.CreateDecryptor(_inputKeyBlock.ServerWriteKey, _inputKeyBlock.ServerWriteIV); _inputKey = _inputKeyBlock.ServerWriteKey; _inputFixedIV = _inputKeyBlock.ServerWriteIV; } else { _inputHasher = _inputCipherSuite.MACAlgorithm.CreateHasher(_inputKeyBlock.ClientWriteMACKey); _decryptor = _inputCipherSuite.BulkCipherAlgorithm.CreateDecryptor(_inputKeyBlock.ClientWriteKey, _inputKeyBlock.ClientWriteIV); _inputKey = _inputKeyBlock.ClientWriteKey; _inputFixedIV = _inputKeyBlock.ClientWriteIV; } }
public void SetUp() { gameObject = new GameObject(); keyBlock = gameObject.AddComponent <KeyBlock>(); gameObject.AddComponent <BoxCollider2D>(); gameObject.AddComponent <SpriteRenderer>(); keyBlock.Start(); keyBlockReplayer = gameObject.AddComponent <KeyBlockReplayer>(); keyBlockReplayer.Start(); }
public void SetCipherSuite(CipherSuite cipherSuite, ConnectionState connectionState) { // Get master secret from connectionState byte[] masterSecret = connectionState.MasterSecret; // Generate seed for changing cipher suite byte[] seed = new byte[64]; Array.Copy(connectionState.ServerRandom, 0, seed, 0, 32); Array.Copy(connectionState.ClientRandom, 0, seed, 32, 32); _nextCipherSuite = cipherSuite; _nextKeyBlock = new KeyBlock(cipherSuite, masterSecret, seed); }
public RecordHandler(ProtocolVersion version, bool isClient) { _isClient = isClient; // Start with NULL cipher suite and key block _nextCipherSuite = new CipherSuite(version); _nextKeyBlock = new KeyBlock(); // Initialize all the other variables ChangeLocalState(); ChangeRemoteState(); _inputEpoch = 0; _outputEpoch = 0; }
static void StringEncryptDecrypt() { KeyBlock encKey = new KeyBlock(64, "SeedPassword123*"); string Original1 = "Some string shorter than 64"; string Original2 = "Some string longer than 64 which is the same as the shorter one but with extra words to make it longer."; string Original3 = "Some string longer than 64 which is the same as the shorter one but with extra words to make it longer but I want to go all the way past 128."; Console.WriteLine(); Console.WriteLine(Original1); Console.WriteLine(Original2); Console.WriteLine(Original3); byte[] scrambleBytes1 = EncryptorDecryptor.ScrambleEncrypt(Encoding.UTF8.GetBytes(Original1), encKey); byte[] scrambleBytes2 = EncryptorDecryptor.ScrambleEncrypt(Encoding.UTF8.GetBytes(Original2), encKey); byte[] scrambleBytes3 = EncryptorDecryptor.ScrambleEncrypt(Encoding.UTF8.GetBytes(Original3), encKey); string scrambleString1 = Encoding.UTF8.GetString(scrambleBytes1); string scrambleString2 = Encoding.UTF8.GetString(scrambleBytes2); string scrambleString3 = Encoding.UTF8.GetString(scrambleBytes3); Console.WriteLine(); Console.WriteLine(scrambleString1); Console.WriteLine(scrambleString2); Console.WriteLine(scrambleString3); KeyBlock decKey = new KeyBlock(64, "SeedPassword123*"); byte[] deScrambled1 = EncryptorDecryptor.ScrambleDecrypt(scrambleBytes1, decKey); byte[] deScrambled2 = EncryptorDecryptor.ScrambleDecrypt(scrambleBytes2, decKey); byte[] deScrambled3 = EncryptorDecryptor.ScrambleDecrypt(scrambleBytes3, decKey); string deScrambledString1 = Encoding.UTF8.GetString(deScrambled1); string deScrambledString2 = Encoding.UTF8.GetString(deScrambled2); string deScrambledString3 = Encoding.UTF8.GetString(deScrambled3); Console.WriteLine(); Console.WriteLine(deScrambledString1); Console.WriteLine(deScrambledString2); Console.WriteLine(deScrambledString3); }
public static void KeyBlock(KeyBlock request) { }
public void Start() { // link components block = GetComponent <KeyBlock>(); }
public Task PostKeyBlockAsync(KeyBlock block, CancellationToken token = default(CancellationToken)) => _apiClient.PostKeyBlockAsync(block, token);
public void GetCurrentKeyBlockTest() { KeyBlock k = nativeClient.GetCurrentKeyBlock(); Assert.IsTrue(k.Height > 0); }
public static long TotalLength (KeyBlock kb_first, KeyBlock kb_last) { return kb_last.last - kb_first.first + 1; }
public static void PostKeyBlock(this FlatClient client, KeyBlock block) => client.PostKeyBlockAsync(block).RunAndUnwrap();