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

            return(record);
        }
示例#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);
            }
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#7
0
 public SafeProvider()
 {
     SettingGateway = new SettingGateway();
     AccountGateway = new AccountGatway();
     Cryptor        = new Cryptor();
 }
示例#8
0
 private byte[] GetEncryptedBytes <T>(T content, string password)
 {
     return(Cryptor.GetEncryptedBytes(content, password));
 }