Exemplo n.º 1
0
 public Safe(string password)
 {
     _password   = password;
     Cryptor     = new Cryptor();
     DataGateway = new DataGateway();
     Searcher    = new Searcher();
 }
Exemplo n.º 2
0
        private Record GetRecordFromUri(string recordFileUri)
        {
            var encryptedBytes = DataGateway.GetBytes(recordFileUri);
            var record         = Cryptor.GetDecryptedContent <Record>(encryptedBytes, _password);

            return(record);
        }
Exemplo n.º 3
0
        public bool TryCreateSafeForExistingUser(string userName, string password, out ISafe safe)
        {
            var account = AccountGateway.ReadUserAccount(WorkingDirectory, userName);
            var verifyingWordBytesForCurrentPassword = Cryptor.GetEncryptedBytes(account.VerifyingWord, password);

            try
            {
                var masterPassword = Cryptor.GetDecryptedContent <string>(account.MasterEncryptedPassBytes, password);
                safe = null;

                if (account.VeryifyingWordEncryptedBytes.Length != verifyingWordBytesForCurrentPassword.Length)
                {
                    return(false);
                }
                for (var i = 0; i < account.VeryifyingWordEncryptedBytes.Length; i++)
                {
                    if (account.VeryifyingWordEncryptedBytes[i] != verifyingWordBytesForCurrentPassword[i])
                    {
                        return(false);
                    }
                }
                safe                  = new Safe(masterPassword);
                safe.UserName         = userName;
                safe.WorkingDirectory = WorkingDirectory;
                return(true);
            }
            catch (Exception e)
            {
                safe = null;
                return(false);
            }
        }
Exemplo n.º 4
0
        public void UpsertRecord(Record record)
        {
            var recordFileUri        = GetRecordFileUri(record.Header.Id);
            var encryptedRecordBytes = Cryptor.GetEncryptedBytes(record, _password);

            DataGateway.DeleteFileIfAvailable(recordFileUri);
            DataGateway.PutBytes(recordFileUri, encryptedRecordBytes);
        }
Exemplo n.º 5
0
        public void RetreiveFile(string recordId, string fileId, string fileUri)
        {
            var encryptedFileUri = GetEncryptedFileUri(recordId, fileId);
            var encryptedBytes   = DataGateway.GetBytes(encryptedFileUri);
            var fileByes         = Cryptor.GetDecryptedContent <byte[]>(encryptedBytes, _password);

            DataGateway.PutBytes(fileUri, fileByes);
        }
Exemplo n.º 6
0
        public void StoreFile(string recordId, string fileId, string fileUri)
        {
            var effectiveFile = GetEncryptedFileUri(recordId, fileId);

            var fileBytes      = DataGateway.GetBytes(fileUri);
            var encryptedBytes = Cryptor.GetEncryptedBytes(fileBytes, _password);

            DataGateway.PutBytes(effectiveFile, encryptedBytes);
        }
Exemplo n.º 7
0
 public SafeProvider()
 {
     SettingGateway = new SettingGateway();
     AccountGateway = new AccountGatway();
     Cryptor        = new Cryptor();
 }
Exemplo n.º 8
0
 private byte[] GetEncryptedBytes <T>(T content, string password)
 {
     return(Cryptor.GetEncryptedBytes(content, password));
 }