/// <summary> /// Deserializes the binaries. /// </summary> /// <param name="xmlReader">The XML text reader.</param> /// <param name="xmlStack">The XML stack.</param> private void DeserializeSecureData(XmlReader xmlReader, Stack <string> xmlStack) { xmlStack.Push(XmlConstants.SecureDataConstants.SecureData); AdvanceReader(xmlReader, xmlStack, null, XmlConstants.SecureDataConstants.SecureData, (reader, stack) => { string secureIdAttribute = xmlReader.GetAttribute(XmlConstants.SecureDataConstants.SecureId); Guid secureId = Guid.Empty; if (string.IsNullOrEmpty(secureIdAttribute) || !Guid.TryParse(secureIdAttribute, out secureId)) { ThrowXmlException("SecureData missing a valid secureId.", xmlReader); } string context = xmlReader.GetAttribute(XmlConstants.SecureDataConstants.Context); if (string.IsNullOrEmpty(context)) { ThrowXmlException("SecureData missing non empty context.", xmlReader); } string encodedString = xmlReader.ReadString( ); var data = Convert.FromBase64String(encodedString); SecureDataEntry entry = new SecureDataEntry(secureId, context, data); _secureData.Add(entry); }); }
/// <summary> /// Return empty set of SecureData /// </summary> public IEnumerable <SecureDataEntry> GetSecureData(IProcessingContext context) { if (!StorageProvider.DoesTableExist("_SecureData")) { yield break; } ///// // Query entities that are part of the solution ///// const string sql = @"select s.SecureId, s.Context, s.Data from _SecureData s"; using (IDbCommand command = CreateCommand()) { command.CommandText = sql; using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { Guid?secureId = GetGuid(reader, 0); if (secureId == null) { continue; } var secureContext = reader.GetString(1); if (secureContext == null) { continue; } var dataString = reader.GetString(2); if (dataString == null) { continue; } var bytes = Convert.FromBase64String(dataString); var entry = new SecureDataEntry((Guid)secureId, secureContext, bytes); yield return(entry); } } } }
/// <summary> /// Return the decrypted secure data stored with the tenant. /// </summary> public IEnumerable <SecureDataEntry> GetSecureData(IProcessingContext context) { var result = new List <SecureDataEntry>(); ///// // Query entities that are part of the solution ///// using (IDbCommand command = CreateCommand()) { command.CommandText = "spSecuredDataReadTenant"; command.CommandType = CommandType.StoredProcedure; command.AddParameterWithValue("@tenantId", TenantId); using (IDataReader reader = command.ExecuteReader()) { while (reader.Read()) { if (reader.IsDBNull(0)) { context?.WriteWarning("Unexpected null SecureDataEntry."); continue; } var secureId = reader.GetGuid(0); var secureContext = reader.GetString(1); var data = reader.GetString(2); var entry = new SecureDataEntry(secureId, secureContext, EncryptString(data)); result.Add(entry); } } } return(result); }