protected void PackEncrypted(ICryptor cryptor, byte[] cryptKey) { PutTlvCmd(); EnterBarrierEncrypted(2, Endian.Big, cryptor, cryptKey); PutTlvBody(); LeaveBarrier(); }
public AuthService(BudgetSquirrelContext dbConext, ICryptor cryptor, GateKeeperConfig gateKeeperConfig, IHttpContextAccessor httpContextAccessor) { this.dbConext = dbConext; this.cryptor = cryptor; this.gateKeeperConfig = gateKeeperConfig; this.httpContextAccessor = httpContextAccessor; }
public static string ExtractDwm(IEmbeder embeder, ICryptor cryptor, Key key, Container container) { byte[] byteMessage = embeder.Extract(container, key); Stream message = cryptor.Decrypt(StreamHelper.BytesToStream(byteMessage), key); return StreamHelper.StreamToString(message); }
/// <summary> /// Initializes a new instance of the <see cref="NoteViewModel"/> class. /// </summary> public NoteViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IThemeService themeService, IBaseUrlService webviewBaseUrl, SearchableHtmlConverter searchableTextConverter, IRepositoryStorageService repositoryService, IFeedbackService feedbackService, ISettingsService settingsService, ICryptor cryptor, SafeListModel safes, NoteModel noteFromRepository) : base(navigationService, languageService, svgIconService, themeService, webviewBaseUrl) { _repositoryService = repositoryService; _feedbackService = feedbackService; _settingsService = settingsService; _searchableTextConverter = searchableTextConverter; _cryptor = cryptor; _safes = safes; MarkSearchableContentAsDirty(); PushNoteToOnlineStorageCommand = new RelayCommand(PushNoteToOnlineStorage); PullNoteFromOnlineStorageCommand = new RelayCommand(PullNoteFromOnlineStorage); ToggleShoppingModeCommand = new RelayCommand(ToggleShoppingMode); GoBackCommand = new RelayCommand(GoBack); Model = noteFromRepository; _unlockedContent = IsInSafe ? UnlockIfSafeOpen(Model.HtmlContent) : Model.HtmlContent; }
/// <inheritdoc/> public ShortenedNoteViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IThemeService themeService, IBaseUrlService webviewBaseUrl, SearchableHtmlConverter searchableTextConverter, IRepositoryStorageService repositoryService, IFeedbackService feedbackService, ISettingsService settingsService, ICryptor cryptor, SafeListModel safes, NoteModel noteFromRepository) : base(navigationService, languageService, svgIconService, themeService, webviewBaseUrl, searchableTextConverter, repositoryService, feedbackService, settingsService, cryptor, safes, noteFromRepository) { if (_unlockedContent != null) { // Create a short version for large notes, with only the first part of the note. // This is a performance improvement if there are large notes in the repository. HtmlShortener shortener = new HtmlShortener(); shortener.WantedLength = 600; // Should be enough even for settings with shortener.WantedTagNumber = 20; // small font and very height notes. string shortenedContent = shortener.Shorten(_unlockedContent); if (shortenedContent.Length != _unlockedContent.Length) { // Because the note will be truncated, we have to build the searchable content // first, before overwriting the original content. string dummy = SearchableContent; _unlockedContent = shortenedContent; } } }
protected override void Given() { cryptor = new SimpleCryptor(); signatureProvider = new SignatureProvider(cryptor); signatureSettings = new SignatureSettings("aKey", "aPassword", expiry); }
public AccountService(IUserRepository userRepository, BudgetSquirrelContext context, ICryptor cryptor, GateKeeperConfig gateKeeperConfig) { this.userRepository = userRepository; this.context = context; this.cryptor = cryptor; this.gateKeeperConfig = gateKeeperConfig; }
/// <summary> /// Initializes a new instance of the <see cref="RecycleBinViewModel"/> class. /// </summary> public RecycleBinViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IThemeService themeService, IBaseUrlService webviewBaseUrl, IFeedbackService feedbackService, ISettingsService settingsService, ICryptoRandomSource randomSource, IRepositoryStorageService repositoryService) : base(navigationService, languageService, svgIconService, themeService, webviewBaseUrl) { _feedbackService = feedbackService; _settingsService = settingsService; _repositoryService = repositoryService; _noteCryptor = new Cryptor(NoteModel.CryptorPackageName, randomSource); RecycledNotes = new List <NoteViewModel>(); _repositoryService.LoadRepositoryOrDefault(out NoteRepositoryModel noteRepository); Model = noteRepository; // Initialize commands GoBackCommand = new RelayCommand(GoBack); RestoreNoteCommand = new RelayCommand <object>(RestoreNote); EmptyRecycleBinCommand = new RelayCommand(EmptyRecycleBin); }
public async Task Decrypt(MessageModel messageModel) { ICryptor cryptor = CryptorFactory.CreateInstance(messageModel.CryptorType); messageModel.Message = await cryptor.Decrypt(messageModel); await Clients.Caller.SendAsync("GetDecryptNewMessage", messageModel); }
public ShadowsocksAdapter(string srv, int port, ICryptor _cryptor, TcpSocket socket, TunInterface tun) : base(socket, tun) { server = srv; this.port = port; cryptor = _cryptor; Init(); }
public async Task CreateNewMessage(MessageModel messageModel) { messageModel.ToLongTimeString = DateTime.Now.ToLongTimeString(); ICryptor cryptor = CryptorFactory.CreateInstance(messageModel.CryptorType); messageModel.Message = await cryptor.Encrypt(messageModel); await Clients.All.SendAsync("GetEncryptNewMessage", messageModel); }
public PasswordProjectStor(ISerializationHelper <PaswordProjectDataStor> serializationHelper , ICryptor cryptor , ISign sign , IFileReadWriteHelper fileReadWrite) { SerializationHelper = serializationHelper; Cryptor = cryptor; Sign = sign; FileReadWrite = fileReadWrite; }
protected void EnterBarrierEncrypted(Prefix prefixFlag, Endian endian, ICryptor cryptor, byte[] cryptKey, uint extend = 0) { EnterBarrier(prefixFlag, endian, extend); barEnc = true; barEncBuffer = buffer; barEncLength = bufferLength; barEncCryptor = cryptor; barEncKey = cryptKey; buffer = null; bufferLength = 0; }
protected void EnterBarrierEncrypted(uint lengthSize, Endian endian, ICryptor cryptor, byte[] cryptKey, uint extend = 0) { EnterBarrier(lengthSize, endian, extend); _barEnc = true; _barEncBuffer = _packetBuffer; _barEncLength = _packetLength; _barEncCryptor = cryptor; _barEncKey = cryptKey; _packetBuffer = null; _packetLength = 0; }
/// <summary> /// Initializes a new instance of the <see cref="NoteRepositoryViewModel"/> class. /// </summary> public NoteRepositoryViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IThemeService themeService, IBaseUrlService webviewBaseUrl, IStoryBoardService storyBoardService, IFeedbackService feedbackService, ISettingsService settingsService, IEnvironmentService environmentService, ICryptoRandomSource randomSource, IRepositoryStorageService repositoryService) : base(navigationService, languageService, svgIconService, themeService, webviewBaseUrl) { _storyBoardService = storyBoardService; _repositoryService = repositoryService; _feedbackService = feedbackService; _settingsService = settingsService; _environmentService = environmentService; _noteCryptor = new Cryptor(NoteModel.CryptorPackageName, randomSource); _searchableTextConverter = new SearchableHtmlConverter(); AllNotes = new List <NoteViewModel>(); FilteredNotes = new ObservableCollection <NoteViewModel>(); _repositoryService.LoadRepositoryOrDefault(out NoteRepositoryModel noteRepository); Model = noteRepository; // Initialize commands and events ShowNoteCommand = new RelayCommand <object>(ShowNote); NewNoteCommand = new RelayCommand(NewNote); NewChecklistCommand = new RelayCommand(NewChecklist); DeleteNoteCommand = new RelayCommand <object>(DeleteNote); ClearFilterCommand = new RelayCommand(ClearFilter); SynchronizeCommand = new RelayCommand(Synchronize); ShowTransferCodeCommand = new RelayCommand(ShowTransferCode); ShowSettingsCommand = new RelayCommand(ShowSettings); ShowRecycleBinCommand = new RelayCommand(ShowRecycleBin); ShowExportCommand = new RelayCommand(ShowExport); ShowInfoCommand = new RelayCommand(ShowInfo); OpenSafeCommand = new RelayCommand(OpenSafe); CloseSafeCommand = new RelayCommand(CloseSafe); ChangeSafePasswordCommand = new RelayCommand(ChangeSafePassword); Modified = false; // If a filter was set before e.g. opening a note, set the same filter again. if (!string.IsNullOrEmpty(_lastFilter)) { Filter = _lastFilter; } }
public void SetUp() { _settingGateway = new SettingGatewayForTests(); _settingGateway.SetWorkingDirectory(_initialWorkingDirectory); var safeProvider = new SafeProvider(); _accountGateway = Substitute.For <IAccountGateway>(); _cryptor = Substitute.For <ICryptor>(); safeProvider.SettingGateway = _settingGateway; safeProvider.AccountGateway = _accountGateway; safeProvider.Cryptor = _cryptor; _safeProvider = safeProvider; }
public void keygen_button_Click(object sender, EventArgs e) { int text_size = Math.Max(unciphered_text_box.Text.Length, ciphered_text.Text.Length); byte[] proxy_keys = XorStringGenerator.generate_random_sequence(text_size); int[] keys = new int[text_size]; for (int i = 0; i < text_size; ++i) { keys[i] = (int)proxy_keys[i]; } letter_cryptor = new XorCryptor(alphabet, keys); numeric_cryptor = new XorCryptor(numeric_alphabet, keys); }
protected override void CheckShutdown() { if (IsShutdown) { encLock.Dispose(); decLock.Dispose(); // cryptor?.Dispose(); cryptor = null; // networkReadStream?.Dispose(); networkStream?.Dispose(); r?.Dispose(); // r.Client.Dispose(); } base.CheckShutdown(); }
public NoteRepositoryViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IThemeService themeService, IBaseUrlService webviewBaseUrl, IStoryBoardService storyBoardService, IFeedbackService feedbackService, ISettingsService settingsService, IEnvironmentService environmentService, ICryptoRandomSource randomSource, IRepositoryStorageService repositoryService) : base(navigationService, languageService, svgIconService, themeService, webviewBaseUrl) { _storyBoardService = storyBoardService; _repositoryService = repositoryService; _feedbackService = feedbackService; _settingsService = settingsService; _environmentService = environmentService; _noteCryptor = new Cryptor(NoteModel.CryptorPackageName, randomSource); _searchableTextConverter = new SearchableHtmlConverter(); AllNotes = new List <NoteViewModel>(); FilteredNotes = new ObservableCollection <NoteViewModel>(); _repositoryService.LoadRepositoryOrDefault(out NoteRepositoryModel noteRepository); Model = noteRepository; // Initialize commands and events ShowNoteCommand = new RelayCommand <Guid>(ShowNote); NewNoteCommand = new RelayCommand(NewNote); NewChecklistCommand = new RelayCommand(NewChecklist); DeleteNoteCommand = new RelayCommand <Guid>(DeleteNote); ClearFilterCommand = new RelayCommand(ClearFilter); SynchronizeCommand = new RelayCommand(Synchronize); ShowTransferCodeCommand = new RelayCommand(ShowTransferCode); ShowSettingsCommand = new RelayCommand(ShowSettings); ShowRecycleBinCommand = new RelayCommand(ShowRecycleBin); ShowInfoCommand = new RelayCommand(ShowInfo); OpenSafeCommand = new RelayCommand(OpenSafe); CloseSafeCommand = new RelayCommand(CloseSafe); ChangeSafePasswordCommand = new RelayCommand(ChangeSafePassword); OnPropertyChanged(nameof(FilterButtonMagnifierVisible)); OnPropertyChanged(nameof(FilterButtonCancelVisible)); Modified = false; }
public unsafe virtual uint Decrypt(ReadOnlySpan <byte> data, Span <byte> outData, ICryptor cryptor = null) { if (cryptor == null) { cryptor = this.cryptor; } fixed(byte *dataPtr = &data.GetPinnableReference(), outDataPtr = &outData.GetPinnableReference()) { var outLen = cryptor.Decrypt((ulong)dataPtr, (uint)data.Length, (ulong)outDataPtr, (uint)outData.Length); #pragma warning disable IDE0004 return((uint)outLen); #pragma warning restore IDE0004 } }
/// <summary> /// [離開屏障] 會立即在加入的數據前寫入長度 /// </summary> protected void LeaveBarrier() { if (_barEnc) { byte[] enc = GetEncryptedBytes(_barEncCryptor, _barEncKey); _packetBuffer = _barEncBuffer; _packetLength = _barEncLength; PutBytes(enc); _barEnc = false; _barEncBuffer = null; _barEncLength = 0; _barEncCryptor = null; _barEncKey = null; } InsertPrefix(_packetBuffer, _packetLength + _barExtLen - _barPos - _lenSize, _lenSize, _barPos, _barLenEndian); }
/// <summary> /// [離開屏障] 會立即在加入的數據前寫入長度 /// </summary> protected void LeaveBarrier() { if (barEnc) { byte[] enc = GetEncryptedBytes(barEncCryptor, barEncKey); buffer = barEncBuffer; bufferLength = barEncLength; PutBytes(enc); barEnc = false; barEncBuffer = null; barEncLength = 0; barEncCryptor = null; barEncKey = null; } InsertPrefix(buffer, barPos, bufferLength + barExtLen - barPos - (uint)prefix, prefix, barLenEndian); }
public int Dec( [Argument] string value, [Option('k')] string key, [Option('v')] string iv, [Option('a')][Algorithms] string algorithms = DefaultAlgorithms ) { ICryptor cryptor = algorithms switch { nameof(SupportAlgorithms.TripleDES) => new TripleDESCryptor(key, iv), nameof(SupportAlgorithms.DES) => new DESCryptor(key, iv), _ => throw new ArgumentException() }; Console.WriteLine(cryptor.Decrypt(value)); return(0); }
private void visioner_crypto_logic() { VisionerConfigForm config_form = new VisionerConfigForm(this); VisionerConfig conf; config_form.ShowDialog(this); conf = config_form.conf; if (conf == null) { MessageBox.Show("Dont close configuration window!"); return; } alphabet = conf.Alphabet; letter_cryptor = new Visioner_Cryptor(conf); numeric_cryptor = new Visioner_Cryptor(conf.Keys, numeric_alphabet); }
public PaymentService( IMerchantAcquirerRepository merchantAcquirerRepository, IAcquirerResponseCodeMappingRepository acquirerResponseCodeMappingRepository, IPaymentRepository paymentRepository, IIndex <ProcessorList, IProcessor> processors, ICryptor cryptor, IValidator <PaymentRequestModel> paymentRequestModelValidator, IValidator <MerchantModel> merchantModelValidator, IMapper mapper) { _merchantAcquirerRepository = Guard.IsNotNull(merchantAcquirerRepository, nameof(merchantAcquirerRepository)); _acquirerResponseCodeMappingRepository = Guard.IsNotNull(acquirerResponseCodeMappingRepository, nameof(acquirerResponseCodeMappingRepository)); _paymentRepository = Guard.IsNotNull(paymentRepository, nameof(paymentRepository)); _processors = Guard.IsNotNull(processors, nameof(processors)); _cryptor = Guard.IsNotNull(cryptor, nameof(cryptor)); _paymentRequestModelValidator = Guard.IsNotNull(paymentRequestModelValidator, nameof(paymentRequestModelValidator)); _merchantModelValidator = Guard.IsNotNull(merchantModelValidator, nameof(merchantModelValidator)); _mapper = Guard.IsNotNull(mapper, nameof(mapper)); }
/// <summary> /// Encrypt Shadowsocks request. /// </summary> /// <param name="data">Input data.</param> /// <param name="outData">Output data. Must have enough capacity to hold encrypted data, tags and additional data.</param> /// <param name="cryptor">The cryptor to used. A null value indicates that the connection-wide cryptor should be used.</param> /// <returns>The length of <paramref name="outData"/> used.</returns> public override uint Encrypt(ReadOnlySpan <byte> data, Span <byte> outData, ICryptor cryptor = null) { if (cryptor == null) { cryptor = this.cryptor; } if (data.Length == 0) { // First chunk, fill IV/salt only return((uint)RealEncrypt(Array.Empty <byte>(), Array.Empty <byte>(), outData, cryptor)); } Span <byte> lenData = stackalloc byte[2]; lenData[0] = (byte)(data.Length >> 8); lenData[1] = (byte)(data.Length & 0xFF); var encryptedLenSize = RealEncrypt(lenData, outData.Slice(2, TAG_SIZE), outData.Slice(0, 2), cryptor) + TAG_SIZE; var dataLenSize = RealEncrypt(data, outData.Slice((int)encryptedLenSize + data.Length, TAG_SIZE), outData.Slice((int)encryptedLenSize, data.Length), cryptor) + TAG_SIZE; return((uint)(encryptedLenSize + dataLenSize)); }
public void TestEncryptorDecryptor() { //FileReadWriteHelper fileReadWriteHelper = new FileReadWriteHelper(privateKeyDirectoryPath, fileName); //AESCryptor aESCryptor = new AESCryptor(new JsonSerializationHelper<KeyValuePair<String, String>>(),fileReadWriteHelper); ICryptor aESCryptor = Factory.CreateCryptor(); String encrypted = Convert.ToBase64String(aESCryptor.Encryptor(Encoding.UTF8.GetBytes(input))); Assert.IsNotNull(encrypted); Console.WriteLine(encrypted); String outPut = Encoding.UTF8.GetString(aESCryptor.Decryptor(Convert.FromBase64String(encrypted))); Assert.IsNotNull(outPut); Console.WriteLine(outPut); Console.WriteLine(outPut.Length - input.Length); Assert.IsTrue(outPut.Length > 0); Assert.IsTrue(outPut.Length == input.Length); }
private void xor_crypto_logic() { XorConfigForm config_form = new XorConfigForm(this); Configs.XorConfig conf; config_form.ShowDialog(this); conf = config_form.conf; if (conf == null) { MessageBox.Show("Dont close configuration window!"); return; } alphabet = conf.Alphabet; letter_cryptor = new XorCryptor(conf); numeric_cryptor = new XorCryptor(numeric_alphabet, conf.Keys); binary_key_textbox.Text = get_binary_string(conf.Keys); }
public ExportViewModel( INavigationService navigationService, ILanguageService languageService, ISvgIconService svgIconService, IThemeService themeService, IBaseUrlService webviewBaseUrl, IFeedbackService feedbackService, ICryptoRandomSource randomSource, IRepositoryStorageService repositoryService, IFolderPickerService folderPickerService) : base(navigationService, languageService, svgIconService, themeService, webviewBaseUrl) { _feedbackService = feedbackService; _repositoryService = repositoryService; _folderPickerService = folderPickerService; _noteCryptor = new Cryptor(NoteModel.CryptorPackageName, randomSource); GoBackCommand = new RelayCommand(GoBack); CancelCommand = new RelayCommand(Cancel); OkCommand = new RelayCommand(Ok); ExportUnprotectedNotes = true; }
private bool TryDecryptRepositoryWithTransfercode(ICryptor decryptor, byte[] binaryCloudRepository, string transferCode, out byte[] decryptedRepository) { try { decryptedRepository = decryptor.Decrypt(binaryCloudRepository, CryptoUtils.StringToSecureString(transferCode)); return(true); } catch (CryptoExceptionInvalidCipherFormat) { // If the downloaded repository is invalid, this is serious and we should not continue throw; } catch (CryptoUnsupportedRevisionException) { throw; } catch (Exception) { // Could not decrypt with this transfercode decryptedRepository = null; return(false); } }
public void SetUp() { _dataGateway = Substitute.For <IDataGateway>(); _cryptor = Substitute.For <ICryptor>(); _safe = new Safe(_password); _safe.WorkingDirectory = _safeWorkingDirectory; _safe.UserName = _userName; _safe.DataGateway = _dataGateway; _safe.Cryptor = _cryptor; _record = new Record { FileRecords = new List <FileRecord>(), PasswordRecords = new List <PasswordRecord>(), Header = new RecordHeader { Id = _recordId, Name = _recordName, Tags = _recordTags } }; }
public AccountController(ICryptor cryptor) { _cryptor = cryptor; }
public AuthController(IAuthProvider authProvider, IUsersRepository usersRepository, ICryptor cryptor) { _authProvider = authProvider; _usersRepository = usersRepository; _cryptor = cryptor; }
public AsyncWorldPaketReceiver(Socket socket, ICryptor cryptor) : base(socket, cryptor) { }
public SignatureProvider(ICryptor cryptor) { _cryptor = cryptor; }
/// <summary> /// Embeds DWM within container. /// </summary> /// <param name="cryptor">Crypt algorithm.</param> /// <param name="embeder">Embeding algorithm.</param> /// <param name="message">Secret message.</param> /// <param name="key">Crypting key.</param> /// <param name="container">Container.</param> /// <param name="fileName">Container file name.</param> /// <returns>Saved file name at server.</returns> public static void EmbedDwm(ICryptor cryptor, IEmbeder embeder, string message, Key key, Container container) { Stream cryptedMessage = cryptor.Encrypt(StreamHelper.StringToStream(message), key); embeder.Embed(container, StreamHelper.StreamToBytesArray(cryptedMessage)); }
public WorldPacketSender(Socket socket, ICryptor cryptor) : base(socket) { this.cryptor = cryptor; }
public AuthProvider(IUserRepository usersRepository, ICryptor cryptor) { _usersRepository = usersRepository; _cryptor = cryptor; }
public AccountController(ICryptor cryptor, IAccountRepository accountRepository) { _cryptor = cryptor; _accountRepository = accountRepository; }