コード例 #1
0
ファイル: SafeByte.cs プロジェクト: qcjxberin/SafeOrbit
        private void Encrypt(byte b)
        {
            //Mix the with arbitrary bytes
            _realBytePosition = _fastRandom.GetInt(0, SaltSize);
            var arbitraryBytes = _fastRandom.GetBytes(SaltSize);

            RuntimeHelper.ExecuteCodeWithGuaranteedCleanup(
                //Action
                () =>
            {
                arbitraryBytes[_realBytePosition] = b;
                //Get key
                _encryptionKey = _fastRandom.GetBytes(KeySize);
                //Encrypt
                var encryptedBuffer = _encryptor.Encrypt(arbitraryBytes, _encryptionKey);
                RuntimeHelper.ExecuteCodeWithGuaranteedCleanup(
                    //Action
                    () =>
                {
                    //Add arbitrary bytes
                    _encryptedByteLength = encryptedBuffer.Length;
                    _encryptedByte       = GetMemoryProtectableSizedBytes(encryptedBuffer);
                },
                    //Cleanup
                    () =>
                {
                    if (encryptedBuffer != null)
                    {
                        Array.Clear(encryptedBuffer, 0, encryptedBuffer.Length);
                    }
                });
            },
                //Cleanup
                () =>
            {
                Array.Clear(arbitraryBytes, 0, arbitraryBytes.Length);
            });
        }
コード例 #2
0
ファイル: SafeBytes.cs プロジェクト: qcjxberin/SafeOrbit
        private void AddArbitraryByte()
        {
            var safeByte = _safeByteFactory.GetByByte((byte)_fastRandom.GetInt(0, 256));

            _safeByteCollection.Append(safeByte);
        }