2013-01-17 113 views
0

我正在使用plist将数十个数据解析到tableview中。它工作得很好。然而,这是不受保护的。如果他打开.ipa文件的内容,有人可以轻松地访问该plist文件。我想保护我的数据。无论如何保护.plist文件?据我所知,Sqlite通过将值更改为复杂键来保护数据。然而,如果我要为我的应用使用sqlite,我必须改变将数据解析为字符串的方式。我对SQLite一无所知。我想将.plist转换为sqlite

从哪里开始?你有什么建议?在ios应用程序中保护数据是否有更简单更好的方法?

在此先感谢。我的plist的

例子:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<array> 
    <dict> 
     <key>quizName</key> 
     <string>History</string> 
     <key>quizDescription</key> 
     <string>Check your knowledge about great historical events, who did what where to whom!</string> 
     <key>quizImageName</key> 
     <string>quiz-history.png</string> 
     <key>questions</key> 
     <array> 
      <dict> 
       <key>question</key> 
       <string>In monarchy, for how long does the head of state rule?</string> 
       <key>answers</key> 
       <array> 
        <string>5 years</string> 
        <string>until someone else is elected</string> 
        <string>as long as he/she is the party leader</string> 
        <string>until death or abdication</string> 
       </array> 
       <key>correctAnswerIndex</key> 
       <integer>3</integer> 
      </dict> 
      <dict> 
       <key>question</key> 
       <string>When was World War 2 fought?</string> 
       <key>answers</key> 
       <array> 
        <string>1935 - 1939</string> 
        <string>1914 - 1918</string> 
        <string>1939 - 1945</string> 
        <string>1918 - 1939</string> 
       </array> 
       <key>correctAnswerIndex</key> 
       <integer>2</integer> 
      </dict> 
      <dict> 
       <key>question</key> 
       <string>Peloponnesian War was famous greek war between...</string> 
       <key>answers</key> 
       <array> 
        <string>Athens and Sparta</string> 
        <string>Greece and Persia</string> 
        <string>Athens and Attica</string> 
        <string>Greece and Macedonia</string> 
       </array> 
       <key>correctAnswerIndex</key> 
       <integer>0</integer> 
      </dict> 
      <dict> 
       <key>question</key> 
       <string>Battle of the Pyramids was fought between which two forces?</string> 
       <key>answers</key> 
       <array> 
        <string>Egypt and Rome</string> 
        <string>French and Mamluk</string> 
        <string>Egypt and Persia</string> 
        <string>Mamluk and Rome</string> 
       </array> 
       <key>correctAnswerIndex</key> 
       <integer>1</integer> 
      </dict> 
      <dict> 
       <key>question</key> 
       <string>First Winter Olypmics were held in...</string> 
       <key>answers</key> 
       <array> 
        <string>Italy, 1920</string> 
        <string>Germany, 1921</string> 
        <string>England, 1928</string> 
        <string>France, 1924</string> 
       </array> 
       <key>correctAnswerIndex</key> 
       <integer>3</integer> 
      </dict> 
     </array> 
    </dict> 
    <dict> 
     <key>quizName</key> 
     <string>Animal kingdom</string> 
     <key>quizDescription</key> 
     <string>Not sure how many legs does the spider have? Test your knowledge and find out!</string> 
     <key>quizImageName</key> 
     <string>quiz-animals.png</string> 
     <key>questions</key> 
     <array> 
      <dict> 
       <key>question</key> 
       <string>Where were the cats domesticated?</string> 
       <key>answers</key> 
       <array> 
        <string>In Greece, around 500 B.C.</string> 
        <string>In ancient Egypt, around 1.600 B.C.</string> 
        <string>In China, around 2.000 B.C.</string> 
        <string>In Mongolia, around 1.400 B.C.</string> 
       </array> 
       <key>correctAnswerIndex</key> 
       <integer>1</integer> 
      </dict> 
      <dict> 
       <key>question</key> 
       <string>Dogs have a range of hearing of...</string> 
       <key>answers</key> 
       <array> 
        <string>approximately 40 Hz to 60,000 Hz</string> 
        <string>approximately 10,000 Hz to 60,000 Hz</string> 
        <string>approximately 40 Hz to 5,000 Hz</string> 
        <string>approximately 5,000 Hz to 30,000 Hz</string> 
       </array> 
       <key>correctAnswerIndex</key> 
       <integer>0</integer> 
      </dict> 
      <dict> 
       <key>question</key> 
       <string>Meerkats can be found where?</string> 
       <key>answers</key> 
       <array> 
        <string>Australia</string> 
        <string>north Africa and south-west Asia</string> 
        <string>south Africa</string> 
        <string>Africa and Australia</string> 
       </array> 
       <key>correctAnswerIndex</key> 
       <integer>2</integer> 
      </dict> 
      <dict> 
       <key>question</key> 
       <string>Biggest mammal is...</string> 
       <key>answers</key> 
       <array> 
        <string>Blue whale</string> 
        <string>Elephant</string> 
        <string>Killer whale</string> 
        <string>Rhinoceros</string> 
       </array> 
       <key>correctAnswerIndex</key> 
       <integer>0</integer> 
      </dict> 
      <dict> 
       <key>question</key> 
       <string>Which of these animals sheads it&apos;s skin?</string> 
       <key>answers</key> 
       <array> 
        <string>monkey</string> 
        <string>narwal</string> 
        <string>snake</string> 
        <string>cow</string> 
       </array> 
       <key>correctAnswerIndex</key> 
       <integer>2</integer> 
      </dict> 
     </array> 
    </dict> 
</array> 
</plist> 
+0

到目前为止您尝试过什么?另外需要注意的是,使用SQLite肯定不适合(本身)保护数据。 – Till

+1

我不认为转换到sqlite真的做任何事情,只要保护 - 人们仍然可以只使用'sqlite3'工具来捅你的数据库。也许考虑问一个关于* data protection *的问题,而不是关于sqlite。 – Tim

回答

1

如果你想要的是加密您的plist文件,然后看看at this SO question

如果你真的想要sqlite,那么不要直接与sqlite打交道,看看CoreData。核心数据是一个Apple框架,使用NSObject和关系可以非常容易地存储和获取数据。如果需要,核心数据可以使用sqlite进行存储。学习曲线相当陡峭,但值得学习,因为它是一个非常有用的框架。

请记住,sqlite数据库只存储在任何人都可以默认阅读的文件中。所以你需要更多的努力来加密它。

+0

+1为加密问题的链接 - 这似乎解决了真正的问题。 – Tim

+0

@Tim:很好的电话,我已经把这个链接移到了第一行,让它更加强调。 – nebs