コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
        public void SetUp()
        {
            gameObject = new GameObject();

            keyBlock = gameObject.AddComponent <KeyBlock>();
            gameObject.AddComponent <BoxCollider2D>();
            gameObject.AddComponent <SpriteRenderer>();
            keyBlock.Start();

            keyBlockReplayer = gameObject.AddComponent <KeyBlockReplayer>();
            keyBlockReplayer.Start();
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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;
        }
コード例 #7
0
ファイル: RecordHandler.cs プロジェクト: juhovh/AaltoTLS
        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;
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: Hans-455/ScrambleEncrypt
        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);
        }
コード例 #9
0
 public static void KeyBlock(KeyBlock request)
 {
 }
コード例 #10
0
        public void Start()
        {
            // link components

            block = GetComponent <KeyBlock>();
        }
コード例 #11
0
 public Task PostKeyBlockAsync(KeyBlock block, CancellationToken token = default(CancellationToken)) => _apiClient.PostKeyBlockAsync(block, token);
コード例 #12
0
ファイル: RecordHandler.cs プロジェクト: juhovh/AaltoTLS
        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);
        }
コード例 #13
0
ファイル: ChainApiTest.cs プロジェクト: block-m3/aepp-sdk-net
        public void GetCurrentKeyBlockTest()
        {
            KeyBlock k = nativeClient.GetCurrentKeyBlock();

            Assert.IsTrue(k.Height > 0);
        }
コード例 #14
0
ファイル: RecordHandler.cs プロジェクト: juhovh/AaltoTLS
        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);
        }
コード例 #15
0
ファイル: statement.cs プロジェクト: alisci01/mono
			public static long TotalLength (KeyBlock kb_first, KeyBlock kb_last)
			{
				return kb_last.last - kb_first.first + 1;
			}
コード例 #16
0
 public static void PostKeyBlock(this FlatClient client, KeyBlock block) => client.PostKeyBlockAsync(block).RunAndUnwrap();
コード例 #17
0
ファイル: RecordHandler.cs プロジェクト: juhovh/AaltoTLS
        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;
            }
        }