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); } }
public void UpsertRecord(Record record) { var recordFileUri = GetRecordFileUri(record.Header.Id); var encryptedRecordBytes = Cryptor.GetEncryptedBytes(record, _password); DataGateway.DeleteFileIfAvailable(recordFileUri); DataGateway.PutBytes(recordFileUri, encryptedRecordBytes); }
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); }
private byte[] GetEncryptedBytes <T>(T content, string password) { return(Cryptor.GetEncryptedBytes(content, password)); }