XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

Save Encryption

Last post 8/7/2008 3:43 PM by CDarklock. 4 replies.
  • 8/7/2008 1:08 AM

    Save Encryption

    I'm using the GUID libraries to create and save player profiles and save game data (saves as traditional XML and uses an XML stream to read).  I need a way to encrypt these files so they're all scrambled when someone opens them in an editor.  Here's an example of my standard SaveGame() method:  (NOTE: the Encrypt() line was recently added and doesn't seem to work)

    1         public void SaveGame() 
    2         { 
    3             m_Game.g_States.StoreState(); 
    4  
    5             m_Game.g_States.ResetStates(); 
    6             m_Game.g_States.Saving = true
    7  
    8             PlayerProfile.Player savePlayer; 
    9             savePlayer = new PlayerProfile.Player(); 
    10             savePlayer = m_Game.g_Player.GetPlayerInfo(); 
    11  
    12             IAsyncResult storageResult; 
    13             StorageDevice device; 
    14             storageResult = Guide.BeginShowStorageDeviceSelector(PlayerIndex.One, nullnull); 
    15             if (storageResult.IsCompleted) 
    16             { 
    17                 device = Guide.EndShowStorageDeviceSelector(storageResult); 
    18                 StorageContainer container = device.OpenContainer("PongRPG"); 
    19                 File.Delete(container.Path + "/savegame" + savePlayer.saveSlot + ".sav"); 
    20  
    21                 string filename = Path.Combine(container.Path, "savegame" + savePlayer.saveSlot + ".sav"); 
    22  
    23                 FileStream stream = File.Open(filename, FileMode.OpenOrCreate); 
    24                  
    25                 // Convert the object to XML data and put it in the stream. 
    26                 XmlSerializer serializer = new XmlSerializer(typeof(PlayerProfile.Player)); 
    27                 serializer.Serialize(stream, savePlayer); 
    28  
    29                 stream.Close(); 
    30  
    31                 // Dispose the container, to commit the data. 
    32                 container.Dispose(); 
    33  
    34                 File.Encrypt(filename); 
    35                  
    36             } 
    37  
    38             //Go back! 
    39             m_Game.g_States.RestoreState(); 
    40         } 

    =========================
    Blog

    Projects
  • 8/7/2008 1:14 AM In reply to

    Re: Save Encryption

    If this is for anything other than a mild 'stop people fiddling' security then why bother. It would take someone only a few minutes to pull the key and the code you use from the assembly.

     

    Play Kissy Poo - a game for 4 year olds on Xbox and windows
    The ZBuffer
    News and information for XNA
      Follow The Zman on twitter, Email me
        Please read the forum FAQs - Bug/Feature reporting
          Don't forget to mark good answers and good playtest feedback when you see it!!!
  • 8/7/2008 3:00 AM In reply to

    Re: Save Encryption

    XNAtticus:
    I need a way to encrypt these files

    What's your question?

    XNAtticus:
    recently added and doesn't seem to work

    How can you tell?

    The ZMan:
    It would take someone only a few minutes to pull the key and the code you use from the assembly.

    It takes someone only a few minutes to pick a lock, too, but I still lock my doors - because most people don't pick locks.

  • 8/7/2008 1:51 PM In reply to

    Re: Save Encryption

    CDarklock:

    XNAtticus:
    I need a way to encrypt these files

    What's your question?

    XNAtticus:
    recently added and doesn't seem to work

    How can you tell?

    The ZMan:
    It would take someone only a few minutes to pull the key and the code you use from the assembly.

    It takes someone only a few minutes to pick a lock, too, but I still lock my doors - because most people don't pick locks.

    I know it doesn't work because it will save my game and I can go grab the file, open it, and it's still viewable as a basic XML document.  I want it to look scrambled when I open it somehow (basically like changing "Test" into "asihdoiahs" or something).  How do I do this?  My friend built a basic C# app that did this although I'm not sure what he used to do it.

    If they're that serious about going into my assembly, pulling the code, and cracking it, I'm fine with that.  But most general home users won't bother with that (granted there won't be loads of people playing).  I'd just feel better with it somewhat protected.

    =========================
    Blog

    Projects
  • 8/7/2008 3:43 PM In reply to

    Re: Save Encryption

    XNAtticus:
    I know it doesn't work because it will save my game and I can go grab the file, open it, and it's still viewable as a basic XML document.

    Then File.Encrypt() is not what you want. The account which encrypts the file can still view the file transparently; only other accounts can't view it. Use something from System.Security.Cryptography instead, or create your save process under alternate credentials.

Page 1 of 1 (5 items) Previous Next