public HashedBlockStream(Stream sBaseStream, bool bWriting, int nBufferSize,
            bool bVerify, ICanSHA256Hash sha256Hasher)
        {
            _sha256Hasher = sha256Hasher;
            if (sBaseStream == null)
                throw new ArgumentNullException("sBaseStream");
            if (nBufferSize < 0)
                throw new ArgumentOutOfRangeException("nBufferSize");

            if (nBufferSize == 0) nBufferSize = m_nDefaultBufferSize;

            m_sBaseStream = sBaseStream;
            m_bWriting = bWriting;
            m_bVerify = bVerify;

            UTF8Encoding utf8 = new UTF8Encoding(false, false);
            if (m_bWriting == false) // Reading mode
            {
                if (m_sBaseStream.CanRead == false)
                    throw new InvalidOperationException();

                m_brInput = new BinaryReader(sBaseStream, utf8);

                m_pbBuffer = new byte[0];
            }
            else // Writing mode
            {
                if (m_sBaseStream.CanWrite == false)
                    throw new InvalidOperationException();

                m_bwOutput = new BinaryWriter(sBaseStream, utf8);

                m_pbBuffer = new byte[nBufferSize];
            }
        }
示例#2
0
 public static async Task<KcpKeyFile> Create(IFile storageFile, ICanSHA256Hash hasher)
 {
     var kcpKeyFile = new KcpKeyFile();
     _hasher = hasher;
     await kcpKeyFile.Init(storageFile);
     return kcpKeyFile;
 }
        public OpenDatabaseViewModel(
            INavigationService navigationService,
            IDatabaseInfoRepository databaseInfoRepository,
            ICanSHA256Hash hasher,
            IDialogService dialogService,
            IPWDatabaseDataSource databaseSource,
            ICache cache)
        {
            _cache = cache;
            _databaseSource = databaseSource;
            _dialogService = dialogService;
            _databaseInfoRepository = databaseInfoRepository;
            _hasher = hasher;
            _navigationService = navigationService;
            var canHitOpen = this.WhenAny(
                vm => vm.Password, 
                vm => vm.KeyFileName,
                (p, k) => !string.IsNullOrEmpty(p.Value) || !string.IsNullOrEmpty(k.Value));

            OpenCommand = new ReactiveCommand(canHitOpen);
            OpenCommand.Subscribe(OpenDatabase);

            GetKeyFileCommand = new ReactiveCommand();
            GetKeyFileCommand.Subscribe(GetKeyFile); 
            
            ClearKeyFileCommand = new ReactiveCommand();
            ClearKeyFileCommand.Subscribe(ClearKeyFile);

            IObservable<string> keyFileNameChanged = this.WhenAny(vm => vm.KeyFileName, kf => kf.Value);
            keyFileNameChanged.Subscribe(v => ClearKeyFileButtonIsVisible = !string.IsNullOrWhiteSpace(v));
            keyFileNameChanged.Subscribe(v => GetKeyFileButtonIsVisible = string.IsNullOrWhiteSpace(v));
        }
示例#4
0
        public async static Task<KcpPassword> Create(string password, ICanSHA256Hash hasher)
        {
            var kcpPassword = new KcpPassword();

            await kcpPassword.Init(UTF8Encoding.UTF8.GetBytes(password), hasher);

            return kcpPassword;
        }
 public PWDatabaseDataSource(IEncryptionEngine encryptionEngine,
     IKeyTransformer keyTransformer,
     IGZipStreamFactory gzipStreamFactory,
     ICanSHA256Hash hasher)
 {
     _hasher = hasher;
     _gzipStreamFactory = gzipStreamFactory;
     _keyTransformer = keyTransformer;
     _encryptionEngine = encryptionEngine;
 }
示例#6
0
 public KeyGenerator(ICanSHA256Hash hasher, 
     IKeyTransformer keyTransformer, 
     CompositeKey compositeKey, 
     IProgress<double> progress)
 {             
     _hasher = hasher;
     _keyTransformer = keyTransformer;
     _compositeKey = compositeKey;
     _progress = progress;
 }
 public KdbWriterFactory(IEncryptionEngine databaseEncryptor, 
     IKeyTransformer keyTransformer, 
     ICanSHA256Hash hasher, 
     IGZipStreamFactory gzipFactory)
 {
     _gzipFactory = gzipFactory;
     _hasher = hasher;
     _keyTransformer = keyTransformer;
     _databaseEncryptor = databaseEncryptor;
 }
示例#8
0
 public Kdb4Reader(Kdb4File kdb4File, 
     IEncryptionEngine databaseDecryptor,
     IKeyTransformer keyTransformer, 
     ICanSHA256Hash hasher,
     IGZipStreamFactory gZipFactory)
 {            
     file = kdb4File;
     _encryptionEngine = databaseDecryptor;
     _keyTransformer = keyTransformer;
     _hasher = hasher;
     _gZipFactory = gZipFactory;
 }
示例#9
0
 public Kdb4Writer(Kdb4HeaderWriter headerWriter,
     IEncryptionEngine databaseEncryptor,
     IKeyTransformer keyTransformer,
     ICanSHA256Hash hasher,
     IGZipStreamFactory gZipFactory)
 {
     this._gZipFactory = gZipFactory;
     this._hasher = hasher;
     this._keyTransformer = keyTransformer;
     this._databaseEncryptor = databaseEncryptor;
     _headerWriter = headerWriter;
 }
        /// <summary>
        /// Construct a new cryptographically secure random stream object.
        /// </summary>
        /// <param name="genAlgorithm">Algorithm to use.</param>
        /// <param name="pbKey">Initialization key. Must not be <c>null</c> and
        /// must contain at least 1 byte.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the
        /// <paramref name="pbKey" /> parameter is <c>null</c>.</exception>
        /// <exception cref="System.ArgumentException">Thrown if the
        /// <paramref name="pbKey" /> parameter contains no bytes or the
        /// algorithm is unknown.</exception>
        public CryptoRandomStream(CrsAlgorithm genAlgorithm, byte[] pbKey, ICanSHA256Hash hasher)
        {
            _hasher = hasher;
            m_crsAlgorithm = genAlgorithm;



            uint uKeyLen = (uint)pbKey.Length;


            if (genAlgorithm == CrsAlgorithm.ArcFourVariant)
            {
                // Fill the state linearly
                m_pbState = new byte[256];
                for (uint w = 0; w < 256; ++w) m_pbState[w] = (byte)w;

                unchecked
                {
                    byte j = 0, t;
                    uint inxKey = 0;
                    for (uint w = 0; w < 256; ++w) // Key setup
                    {
                        j += (byte)(m_pbState[w] + pbKey[inxKey]);

                        t = m_pbState[0]; // Swap entries
                        m_pbState[0] = m_pbState[j];
                        m_pbState[j] = t;

                        ++inxKey;
                        if (inxKey >= uKeyLen) inxKey = 0;
                    }
                }

                GetRandomBytes(512); // Increases security, see cryptanalysis
            }
            else if (genAlgorithm == CrsAlgorithm.Salsa20)
            {


                byte[] pbKey32 = _hasher.Hash(pbKey);
                byte[] pbIV = new byte[]{ 0xE8, 0x30, 0x09, 0x4B,
					0x97, 0x20, 0x5D, 0x2A }; // Unique constant

                m_salsa20 = new Salsa20Cipher(pbKey32, pbIV);
            }
            else // Unknown algorithm
            {
                throw new UnknownAlgorithmException();
            
            }
        }
        public ChooseCloudViewModel(
            INavigationService navigationService,
            IDatabaseInfoRepository databaseInfoRepository,
            ICanSHA256Hash hasher,
            IDialogService dialogService,
            IPWDatabaseDataSource databaseSource,
            ICache cache)
        {
            _cache = cache;
            _databaseSource = databaseSource;
            _dialogService = dialogService;
            _databaseInfoRepository = databaseInfoRepository;
            _hasher = hasher;
            _navigationService = navigationService;

            NavigateToSkyDriveCommand = new ReactiveCommand();
            NavigateToSkyDriveCommand.Subscribe(NavigateToSkyDrive);
            
            NavigateToDropboxCommand = new ReactiveCommand();
            NavigateToDropboxCommand.Subscribe(NavigateToDropbox);

            NavigateToCreateDemoCommand = new ReactiveCommand();
            NavigateToCreateDemoCommand.Subscribe(NavigateToCreateDemo);
        }
示例#12
0
 private async Task Init(byte[] passwordInUTF8,ICanSHA256Hash hasher)
 {
     var hashedBuffer = hasher.Hash(passwordInUTF8);
     keyData = hashedBuffer;
 }
示例#13
0
 public HashedBlockStream(Stream sBaseStream, bool bWriting, int nBufferSize,ICanSHA256Hash SHA256Hasher)
     : this(sBaseStream, bWriting, nBufferSize, true, SHA256Hasher)
 {
 
 }
示例#14
0
 public HashedBlockStream(Stream sBaseStream, bool bWriting, ICanSHA256Hash SHA256Hasher)
     : this(sBaseStream, bWriting, 0, true, SHA256Hasher)
 {
 
 }