public Boolean Process() { Boolean retVal = false; try { _state = Common.NodeState.Processing; DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information | DFramework.Logging.Interfaces.LoggerMessageType.Sensitive, "Processing AESDecryptNode."); if (IV.Value == null) { //Split IV from the data using (MemoryStream dataWithIV = new MemoryStream(EncryptedData.Value)) { Byte[] iv = new Byte[16]; dataWithIV.Read(iv, 0, iv.Length); Byte[] dataBlock = new Byte[dataWithIV.Length - iv.Length]; dataWithIV.Read(dataBlock, 0, dataBlock.Length); IV.SetValue(iv); EncryptedData.SetValue(dataBlock); } } Byte[] inBlock = (Byte[])EncryptedData.Value; DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information | DFramework.Logging.Interfaces.LoggerMessageType.Sensitive, "Creating AES decryptor."); DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information | DFramework.Logging.Interfaces.LoggerMessageType.Sensitive, "Key = {0}.", ((Byte[])Key.Value).ToPrettyString()); DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information | DFramework.Logging.Interfaces.LoggerMessageType.Sensitive, "IV = {0}.", ((Byte[])IV.Value).ToPrettyString()); DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information | DFramework.Logging.Interfaces.LoggerMessageType.Sensitive, "Input = {0}.", inBlock.ToPrettyString()); Byte[] outBlock = AESUtility.DecryptBytes(inBlock, (Byte[])Key.Value, (Byte[])IV.Value); _unencryptedData.SetValue(UnicodeEncoding.Unicode.GetString(outBlock)); retVal = true; } catch (Exception ex) { _state = Common.NodeState.Error; DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.Fail | DFramework.Logging.Interfaces.LoggerMessageType.Exception | DFramework.Logging.Interfaces.LoggerMessageType.Sensitive, "Exception occurred in AESDecryptNode :: {0}", ex.ToString()); retVal = false; } finally { _state = Common.NodeState.Processed; DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information | DFramework.Logging.Interfaces.LoggerMessageType.Sensitive, "Processed AESDecryptNode."); if (retVal) { Processed?.Invoke(this, EventArgs.Empty); } } if (retVal) { if (_next != null && _next.Length > 0) { return(_next[0].Process()); } else { return(true); } } else { return(false); } }
public Boolean Process() { Boolean retVal = false; try { _state = Common.NodeState.Processing; DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information | DFramework.Logging.Interfaces.LoggerMessageType.Sensitive, "Processing AESEncryptNode."); Boolean randomIV = false; if (IV.Value == null) { Byte[] iv = SimpleRandomGenerator.QuickGetRandomBytes(16); IV.SetValue(iv); randomIV = true; } Byte[] inBlock = UnicodeEncoding.Unicode.GetBytes((String)PlainText.Value); DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information | DFramework.Logging.Interfaces.LoggerMessageType.Sensitive, "Creating AES encryptor."); DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information | DFramework.Logging.Interfaces.LoggerMessageType.Sensitive, "Key = {0}.", ((Byte[])Key.Value).ToPrettyString()); DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information | DFramework.Logging.Interfaces.LoggerMessageType.Sensitive, "IV = {0}.", ((Byte[])IV.Value).ToPrettyString()); DLoggerManager.Instance.Logger.Log(DFramework.Logging.Interfaces.LoggerMessageType.VerboseHigh | DFramework.Logging.Interfaces.LoggerMessageType.Information | DFramework.Logging.Interfaces.LoggerMessageType.Sensitive, "Input = {0}.", inBlock.ToPrettyString()); Byte[] outBlock = AESUtility.EncryptBytes(inBlock, (Byte[])Key.Value, (Byte[])IV.Value); if (randomIV) { using (MemoryStream dataWithIV = new MemoryStream()) { dataWithIV.Write(IV.Value, 0, IV.Value.Length); dataWithIV.Write(outBlock, 0, outBlock.Length); dataWithIV.Flush(); _encryptedData.SetValue(dataWithIV.ToArray()); } } else { _encryptedData.SetValue(outBlock); } retVal = true; } finally { _state = Common.NodeState.Processed; if (retVal) { Processed?.Invoke(this, EventArgs.Empty); } } if (retVal) { if (_next != null && _next.Length > 0) { return(_next[0].Process()); } else { return(true); } } else { return(false); } }