public override Task <PlainTextData> Decrypt(EncryptedData request, ServerCallContext context) { return(Task.FromResult(new PlainTextData { UserName = encryptionService.Decrypt(request.UserName, keyToken, ivToken), Password = encryptionService.Decrypt(request.Password, keyToken, ivToken) })); }
public static async ReusableTask <PeerMessage> ReceiveMessageAsync(IConnection connection, IEncryption decryptor, IRateLimiter rateLimiter, ConnectionMonitor peerMonitor, ConnectionMonitor managerMonitor, ITorrentData torrentData, ByteBuffer buffer) { await MainLoop.SwitchToThreadpool(); int messageHeaderLength = 4; int messageBodyLength; ByteBuffer messageHeaderBuffer = buffer; ByteBuffer messageBuffer = buffer; ByteBufferPool.Releaser messageBufferReleaser = default; using (var headerReleaser = buffer == null ? NetworkIO.BufferPool.Rent(messageHeaderLength, out messageHeaderBuffer) : default) { await NetworkIO.ReceiveAsync(connection, messageHeaderBuffer, 0, messageHeaderLength, rateLimiter, peerMonitor?.ProtocolDown, managerMonitor?.ProtocolDown).ConfigureAwait(false); decryptor.Decrypt(messageHeaderBuffer.Data, 0, messageHeaderLength); messageBodyLength = IPAddress.HostToNetworkOrder(BitConverter.ToInt32(messageHeaderBuffer.Data, 0)); if (messageBodyLength < 0 || messageBodyLength > MaxMessageLength) { connection.Dispose(); throw new ProtocolException($"Invalid message length received. Value was '{messageBodyLength}'"); } if (messageBodyLength == 0) { return(new KeepAliveMessage()); } if (buffer == null || buffer.Data.Length < messageBodyLength + messageHeaderLength) { messageBufferReleaser = NetworkIO.BufferPool.Rent(messageBodyLength + messageHeaderLength, out messageBuffer); Buffer.BlockCopy(messageHeaderBuffer.Data, 0, messageBuffer.Data, 0, messageHeaderLength); } } using (messageBufferReleaser) { // Always assume protocol first, then convert to data when we what message it is! await NetworkIO.ReceiveAsync(connection, messageBuffer, messageHeaderLength, messageBodyLength, rateLimiter, peerMonitor?.ProtocolDown, managerMonitor?.ProtocolDown).ConfigureAwait(false); decryptor.Decrypt(messageBuffer.Data, messageHeaderLength, messageBodyLength); // FIXME: manager should never be null, except some of the unit tests do that. var data = PeerMessage.DecodeMessage(messageBuffer.Data, 0, messageHeaderLength + messageBodyLength, torrentData); if (data is PieceMessage msg) { peerMonitor?.ProtocolDown.AddDelta(-msg.RequestLength); managerMonitor?.ProtocolDown.AddDelta(-msg.RequestLength); peerMonitor?.DataDown.AddDelta(msg.RequestLength); managerMonitor?.DataDown.AddDelta(msg.RequestLength); } return(data); } }
public ResourceEntry ToResourceEntry(IEncryption encryption, MamChannelFactory channelFactory, MamChannelSubscriptionFactory subscriptionFactory) { var decryptedChannel = encryption.Decrypt(this.Channel); var decryptedSubscription = encryption.Decrypt(this.Subscription); return(new ResourceEntry { ResourceRoots = this.Roots.Split(';').ToList(), Channel = string.IsNullOrEmpty(decryptedChannel) ? null : channelFactory.CreateFromJson(decryptedChannel), Subscription = subscriptionFactory.CreateFromJson(decryptedSubscription) }); }
public void Should_Encrypt_Data() { //Arrange string Id = "2"; //Act var result = Encryption.Encypt(Id); //Assert Assert.NotNull(result); Assert.AreEqual(Id, Encryption.Decrypt(result)); }
public void SetEncryptedName(string nm) { if (_encrypted_path_name) { _dname = Cryptography.Decrypt(nm, Settings.DefaultPassword); } else { _dname = nm; } _name = nm; }
public static async ReusableTask <PeerMessage> ReceiveMessageAsync(IConnection2 connection, IEncryption decryptor, IRateLimiter rateLimiter, ConnectionMonitor peerMonitor, ConnectionMonitor managerMonitor, ITorrentData torrentData) { byte[] messageLengthBuffer = null; byte[] messageBuffer = null; int messageLength = 4; int messageBody; try { messageLengthBuffer = ClientEngine.BufferPool.Rent(messageLength); await NetworkIO.ReceiveAsync(connection, messageLengthBuffer, 0, messageLength, rateLimiter, peerMonitor?.ProtocolDown, managerMonitor?.ProtocolDown).ConfigureAwait(false); decryptor.Decrypt(messageLengthBuffer, 0, messageLength); messageBody = IPAddress.HostToNetworkOrder(BitConverter.ToInt32(messageLengthBuffer, 0)); if (messageBody < 0 || messageBody > MaxMessageLength) { connection.Dispose(); throw new ProtocolException($"Invalid message length received. Value was '{messageBody}'"); } if (messageBody == 0) { return(new KeepAliveMessage()); } messageBuffer = ClientEngine.BufferPool.Rent(messageBody + messageLength); Buffer.BlockCopy(messageLengthBuffer, 0, messageBuffer, 0, messageLength); } finally { ClientEngine.BufferPool.Return(messageLengthBuffer); } try { // Always assume protocol first, then convert to data when we what message it is! await NetworkIO.ReceiveAsync(connection, messageBuffer, messageLength, messageBody, rateLimiter, peerMonitor?.ProtocolDown, managerMonitor?.ProtocolDown).ConfigureAwait(false); decryptor.Decrypt(messageBuffer, messageLength, messageBody); // FIXME: manager should never be null, except some of the unit tests do that. var data = PeerMessage.DecodeMessage(messageBuffer, 0, messageLength + messageBody, torrentData); if (data is PieceMessage msg) { peerMonitor?.ProtocolDown.AddDelta(-msg.RequestLength); managerMonitor?.ProtocolDown.AddDelta(-msg.RequestLength); peerMonitor?.DataDown.AddDelta(msg.RequestLength); managerMonitor?.DataDown.AddDelta(msg.RequestLength); } return(data); } finally { ClientEngine.BufferPool.Return(messageBuffer); } }
public TokenData DecodeAccessToken(string token) { if (string.IsNullOrWhiteSpace(token)) { throw new ArgumentNullException("token"); } var encryptedBytes = token.FromBase65(); var decryptedBytes = _encryptor.Decrypt(encryptedBytes); return(GetAccessTokenFromBytes(decryptedBytes)); }
public static async Task <PeerMessage> ReceiveMessageAsync(IConnection connection, IEncryption decryptor, IRateLimiter rateLimiter, ConnectionMonitor monitor, TorrentManager manager) { byte[] messageLengthBuffer = null; byte[] messageBuffer = null; int messageLength = 4; int messageBody; try { messageLengthBuffer = ClientEngine.BufferManager.GetBuffer(messageLength); await NetworkIO.ReceiveAsync(connection, messageLengthBuffer, 0, messageLength, rateLimiter, monitor?.ProtocolDown, manager?.Monitor.ProtocolDown).ConfigureAwait(false); decryptor.Decrypt(messageLengthBuffer, 0, messageLength); messageBody = IPAddress.HostToNetworkOrder(BitConverter.ToInt32(messageLengthBuffer, 0));; if (messageBody < 0 || messageBody > MaxMessageLength) { throw new Exception($"Invalid message length received. Value was '{messageBody}'"); } if (messageBody == 0) { return(new KeepAliveMessage()); } messageBuffer = ClientEngine.BufferManager.GetBuffer(messageBody + messageLength); Buffer.BlockCopy(messageLengthBuffer, 0, messageBuffer, 0, messageLength); } finally { ClientEngine.BufferManager.FreeBuffer(messageLengthBuffer); } try { // Always assume protocol first, then convert to data when we what message it is! await NetworkIO.ReceiveAsync(connection, messageBuffer, messageLength, messageBody, rateLimiter, monitor?.ProtocolDown, manager?.Monitor.ProtocolDown).ConfigureAwait(false); decryptor.Decrypt(messageBuffer, messageLength, messageBody); var data = PeerMessage.DecodeMessage(messageBuffer, 0, messageLength + messageBody, manager); if (data is PieceMessage msg) { monitor?.ProtocolDown.AddDelta(-msg.RequestLength); manager?.Monitor.ProtocolDown.AddDelta(-msg.RequestLength); monitor?.DataDown.AddDelta(msg.RequestLength); manager?.Monitor.DataDown.AddDelta(msg.RequestLength); } return(data); } finally { ClientEngine.BufferManager.FreeBuffer(messageBuffer); } }
public byte[] Get(string bucket, string key, string encriptionKey = null) { var path = GetPath(bucket, key); if (!File.Exists(path)) { throw new KeyNotFoundException(key); } byte[] byteData = File.ReadAllBytes(path); if (!string.IsNullOrEmpty(encriptionKey)) { byteData = _encryption.Decrypt(byteData, encriptionKey); } return(byteData); }
public void ExecuteRetrieveFile(object args) { try { var deHideOption = this.GetDeHideOptionFromView((Window)args); if (deHideOption == null) { return; } var ciphertext = HideLSB.DeHide(this._hiddenImageBitmapCache); IEncryption encryptor = EncryptionFactory.CreateEncryption(deHideOption.EncryptionAlg); var plaintext = encryptor.Decrypt(ciphertext, this.StrPassword2UintArr(deHideOption.Password)); var deZipdata = Zip.Decompress(plaintext); if (File.Exists(deHideOption.FilePath)) { File.Delete(deHideOption.FilePath); } FileTransform.ByteArray2File(deHideOption.FilePath, deZipdata); this.ShowMessageBoxResource("RetrieveDone", "Hint", MessageBoxButton.OK, MessageBoxImage.Information); } catch (PasswordWrongException) { this.ShowMessageBoxResource("PasswordWrong", "Error"); } catch (Exception) { this.ShowMessageBoxResource("PasswordWrong", "Error"); } }
public static async ReusableTask <(PeerMessage message, PeerMessage.Releaser releaser)> ReceiveMessageAsync(IPeerConnection connection, IEncryption decryptor, IRateLimiter?rateLimiter, ConnectionMonitor?peerMonitor, ConnectionMonitor?managerMonitor, ITorrentManagerInfo?torrentData, Memory <byte> buffer) { await MainLoop.SwitchToThreadpool(); int messageHeaderLength = 4; int messageBodyLength; Memory <byte> messageHeaderBuffer = buffer; Memory <byte> messageBuffer = buffer; ByteBufferPool.Releaser messageHeaderReleaser = default; ByteBufferPool.Releaser messageBufferReleaser = default; if (messageHeaderBuffer.IsEmpty) { messageHeaderReleaser = NetworkIO.BufferPool.Rent(messageHeaderLength, out messageHeaderBuffer); } using (messageHeaderReleaser) { await NetworkIO.ReceiveAsync(connection, messageHeaderBuffer.Slice(0, messageHeaderLength), rateLimiter, peerMonitor?.ProtocolDown, managerMonitor?.ProtocolDown).ConfigureAwait(false); decryptor.Decrypt(messageHeaderBuffer.Span.Slice(0, messageHeaderLength)); messageBodyLength = Message.ReadInt(messageHeaderBuffer.Span); if (messageBodyLength < 0 || messageBodyLength > MaxMessageLength) { connection.Dispose(); throw new ProtocolException($"Invalid message length received. Value was '{messageBodyLength}'"); } if (messageBodyLength == 0) { return(KeepAliveMessage.Instance, default);
public static PeerMessage ReceiveMessage(CustomConnection connection, IEncryption decryptor, TorrentManager manager) { byte[] buffer = new byte[4]; Receive(connection, buffer, 0, buffer.Length); decryptor.Decrypt(buffer); int count = IPAddress.HostToNetworkOrder(BitConverter.ToInt32(buffer, 0)); byte[] message = new byte[count + 4]; Buffer.BlockCopy(buffer, 0, message, 0, 4); Receive(connection, message, 4, count); decryptor.Decrypt(message, 4, count); return(PeerMessage.DecodeMessage(message, 0, message.Length, manager)); }
public void CanEncryptAndDecrypt() { var text = "adam"; var encrypted = _sut.Encrypt(text); var decrypted = _sut.Decrypt(encrypted); Assert.Equal(text, decrypted); }
public HttpResponseMessage GetActiveStudent(string guid) { var accountId = _encryption.Decrypt(HttpContext.Current.Server.UrlDecode(guid)); var student = _studentsServices.ActivateUser(accountId); var response = Request.CreateResponse(HttpStatusCode.Moved); response.Headers.Location = new Uri("http://fiasps.unitec.edu:8096"); return(response); }
private UserData MaterializeUserData(IDataRecord row) { return(new UserData { UserName = row.Get <string>("username_value"), URL = row.Get <string>("action_url"), Password = _encryption.Decrypt(row.Get <byte[]>("password_value")) }); }
private AppTokenModel DecryptToken(OAuthClient client, string token) { var trimtoken = token.Substring(20, token.Length - 20); _logger.Debug($"DecryptToken id {trimtoken}"); var data = _encryption.Decrypt(trimtoken, client.EncryptionKey); var model = Newtonsoft.Json.JsonConvert.DeserializeObject <AppTokenModel>(data); return(model); }
public string Get(string key) { var dataPath = Path.Combine(Path.GetTempPath(), key + ".tmp"); var keyPath = Path.Combine(Path.GetTempPath(), key + ".key"); var encryptedAesKeyIvPair = File.ReadAllBytes(keyPath); var data = File.ReadAllBytes(dataPath); return(_encryption.Decrypt(new EncryptedItem(encryptedAesKeyIvPair, data), WindowsKeystoreId)); }
public string Read(string path, bool decryptFile) { string text = Read(path); if (!decryptFile) { return(text); } return(encryption.Decrypt(text)); }
public override XmlNode Decrypt(XmlNode encryptedNode) { string decryptedData = encryption.Decrypt(encryptedNode.InnerText); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.PreserveWhitespace = true; xmlDoc.LoadXml(decryptedData); return(xmlDoc.DocumentElement); }
/// <summary> /// Decrypts a value if it begins with the "enc:" prefix; otherwise returns the value. /// </summary> public string Decrypt(string encryptedValue) { if (string.IsNullOrEmpty(encryptedValue) || !encryptedValue.StartsWith(ValuePrefix) || encryptedValue == ValuePrefix) { return(encryptedValue); } encryptedValue = encryptedValue.Substring(ValuePrefix.Length); return(_encryption.Decrypt(encryptedValue)); }
private void btnDecrypt_Click(object sender, EventArgs e) { try { tbTarget.Text = encryption.Decrypt(tbSource.Text.Trim()); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Override read page decrypting data from disk /// </summary> public override byte[] ReadPage(uint pageID) { var buffer = base.ReadPage(pageID); if (pageID == 0) { return(buffer); } return(_crypto.Decrypt(buffer)); }
public static async ReusableTask <HandshakeMessage> ReceiveHandshakeAsync(IPeerConnection connection, IEncryption decryptor) { await MainLoop.SwitchToThreadpool(); using (NetworkIO.BufferPool.Rent(HandshakeMessage.HandshakeLength, out Memory <byte> buffer)) { await NetworkIO.ReceiveAsync(connection, buffer, null, null, null).ConfigureAwait(false); decryptor.Decrypt(buffer.Span); return(new HandshakeMessage(buffer.Span)); } }
public async Task <IPayload> GetPayload(IMessage message) { var data = encryption.Decrypt(message.Data); data = compression.Decompress(data); var @event = eventHolder.GetEvent(message.EventId); var dataType = @event.GetInterfaces()[0].GetGenericArguments()[0]; var @object = serializer.Deserialize(data, dataType); return(await Task.FromResult((IPayload) new Payload { Event = @event, Data = @object }).ConfigureAwait(false)); }
public string Decrypt(string key, string encryptedText) { if (key != null) { //logger.Debug(($"SecurityManager Decrypt({encryptedText}, {key})")); return(encryptor.Decrypt(encryptedText, key, encryptionPassword)); } else { logger.Error(($"SecurityManager Decrypt({encryptedText}, key==null)")); return(encryptedText); } }
public void VerifyProfessor(VerifiedProfessorModel model) { var professor = _professorRepository.GetByAccountId(_encryption.Decrypt(model.AccountId)); if (professor == null) { throw new NotFoundException("No se encontro el professor"); } professor.Password = _encryption.Encrypt(model.Password); professor.Status = Status.Active; _professorRepository.Update(professor); _professorRepository.Save(); }
public void TestHandshake(byte[] buffer, CustomConnection connection) { // 1) Send local handshake SendMessage(new HandshakeMessage(rig.Manager.Torrent.infoHash, new string('g', 20), VersionInfo.ProtocolStringV100, true, false), connection); // 2) Receive remote handshake if (buffer == null || buffer.Length == 0) { buffer = new byte[68]; Receive(connection, buffer, 0, 68); decryptor.Decrypt(buffer); } HandshakeMessage handshake = new HandshakeMessage(); handshake.Decode(buffer, 0, buffer.Length); Assert.AreEqual(rig.Engine.PeerId, handshake.PeerId, "#2"); Assert.AreEqual(VersionInfo.ProtocolStringV100, handshake.ProtocolString, "#3"); Assert.AreEqual(ClientEngine.SupportsFastPeer, handshake.SupportsFastPeer, "#4"); Assert.AreEqual(ClientEngine.SupportsExtended, handshake.SupportsExtendedMessaging, "#5"); // 2) Send local bitfield SendMessage(new BitfieldMessage(rig.Manager.Bitfield), connection); // 3) Receive remote bitfield - have none PeerMessage message = ReceiveMessage(connection); Assert.IsTrue(message is HaveNoneMessage || message is BitfieldMessage, "HaveNone"); // 4) Send a few allowed fast SendMessage(new AllowedFastMessage(1), connection); SendMessage(new AllowedFastMessage(2), connection); SendMessage(new AllowedFastMessage(3), connection); SendMessage(new AllowedFastMessage(0), connection); // 5) Receive a few allowed fast ReceiveMessage(connection); ReceiveMessage(connection); ReceiveMessage(connection); ReceiveMessage(connection); ReceiveMessage(connection); ReceiveMessage(connection); ReceiveMessage(connection); ReceiveMessage(connection); ReceiveMessage(connection); ReceiveMessage(connection); // 6) Receive interested message = ReceiveMessage(connection); Assert.IsTrue(message is InterestedMessage, "Interested"); }
protected void EncryptDecryptTest(IEncryption crypto) { string plainText = GenerateRandomText(1000); string key = GenerateRandomText(5); Trace.WriteLine(string.Format("keyUsed={0}", key)); Trace.WriteLine(string.Format("plainText={0}", plainText)); string encryptedText = crypto.Encrypt(plainText, key); Trace.WriteLine(string.Format("encryptedText={0}", encryptedText)); string unEncryptedText = crypto.Decrypt(encryptedText, key); Assert.AreEqual(plainText, unEncryptedText); }
public static async ReusableTask <HandshakeMessage> ReceiveHandshakeAsync(IConnection connection, IEncryption decryptor) { await MainLoop.SwitchToThreadpool(); using (NetworkIO.BufferPool.Rent(HandshakeMessage.HandshakeLength, out ByteBuffer buffer)) { await NetworkIO.ReceiveAsync(connection, buffer, 0, HandshakeMessage.HandshakeLength, null, null, null).ConfigureAwait(false); decryptor.Decrypt(buffer.Data, 0, HandshakeMessage.HandshakeLength); var message = new HandshakeMessage(); message.Decode(buffer.Data, 0, HandshakeMessage.HandshakeLength); return(message); } }
public static PeerMessage ReceiveMessage(CustomConnection connection, IEncryption decryptor, TorrentManager manager) { byte[] buffer = new byte[4]; Receive (connection, buffer, 0, buffer.Length); decryptor.Decrypt(buffer); int count = IPAddress.HostToNetworkOrder(BitConverter.ToInt32(buffer, 0)); byte[] message = new byte[count + 4]; Buffer.BlockCopy(buffer, 0, message, 0, 4); Receive (connection, message, 4, count); decryptor.Decrypt(message, 4, count); return PeerMessage.DecodeMessage(message, 0, message.Length, manager); }
public static async ReusableTask <HandshakeMessage> ReceiveHandshakeAsync(IConnection2 connection, IEncryption decryptor) { byte[] buffer = ClientEngine.BufferPool.Rent(HandshakeMessage.HandshakeLength); try { await NetworkIO.ReceiveAsync(connection, buffer, 0, HandshakeMessage.HandshakeLength, null, null, null).ConfigureAwait(false); decryptor.Decrypt(buffer, 0, HandshakeMessage.HandshakeLength); var message = new HandshakeMessage(); message.Decode(buffer, 0, HandshakeMessage.HandshakeLength); return(message); } finally { ClientEngine.BufferPool.Return(buffer); } }