<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
  <title>SHRDLU</title>
  <link>https://shrdlu.ch/</link>
  <description>Inconsistent worlds are always fun places to visit</description>
  <language>en</language>
  <atom:link href="https://shrdlu.ch/feed.xml" rel="self" type="application/rss+xml"/>
  <item>
    <title>Music reverse engineered: Ommadawn live in Montreux</title>
    <link>https://shrdlu.ch/music-reverse-engineered-ommadawn-live-in-montreux/</link>
    <guid isPermaLink="true">https://shrdlu.ch/music-reverse-engineered-ommadawn-live-in-montreux/</guid>
    <pubDate>Fri, 29 Sep 2017 18:52:03 -0000</pubDate>
    <content:encoded>&lt;p&gt;Here&#39;s the transcript of an excerpt of Mike Oldfield&#39;s Ommadawn (live in Montreux). It&#39;s the electric guitar part starting at around 1:07:45 right after the fluty fantasia...&lt;/p&gt;
&lt;p&gt;Enjoy! \m/&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;Ommadawn_excerpt.txt&#34;&gt;Ommadawn_Montreux.txt&lt;/a&gt;&lt;/p&gt;</content:encoded>
  </item>
  <item>
    <title>Music reverse engineered: Incantations (excerpt)</title>
    <link>https://shrdlu.ch/music-reverse-engineered-incantations-excerpt/</link>
    <guid isPermaLink="true">https://shrdlu.ch/music-reverse-engineered-incantations-excerpt/</guid>
    <pubDate>Sun, 24 Apr 2016 15:52:03 -0000</pubDate>
    <content:encoded>&lt;p&gt;Here&#39;s the transcription of a small piece from Mike Oldfield&#39;s Incantations 1 &amp;amp; 2 - from the &lt;strong&gt;Exposed&lt;/strong&gt; album (13:12min - 14:17min). Actually it&#39;s the beginning of Part 2 played on an electric guitar.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;Incantations_Part_1_2.txt&#34;&gt;Incantations.txt&lt;/a&gt;&lt;/p&gt;</content:encoded>
  </item>
  <item>
    <title>Music reverse engineered: Shabda &amp; Aurora</title>
    <link>https://shrdlu.ch/music-reverse-engineered-shabda-aurora/</link>
    <guid isPermaLink="true">https://shrdlu.ch/music-reverse-engineered-shabda-aurora/</guid>
    <pubDate>Wed, 25 Dec 2013 13:20:12 -0000</pubDate>
    <content:encoded>&lt;p&gt;I have ignored Music of the Spheres for a long time. After a discussion with my &lt;a href=&#34;http://aasemoon.com&#34;&gt;friend&lt;/a&gt; a few weeks ago I decided to give it another try. Conclusion: I&#39;m still not sure how to compare it to classics like Hergest Ridge, Ommadawn, etc. but it certainly doesn&#39;t deserve to be ignored. And Shabda is a masterpiece.&lt;br /&gt;
Here&#39;s transcriptions for Shabda and Aurora. I hope you enjoy playing!&lt;br /&gt;
Suggestions and corrections are highly appreciated.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;Aurora1.txt&#34;&gt;Aurora.txt&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;Shabda1.txt&#34;&gt;Shabda.txt&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Merry Christmas!&lt;/p&gt;</content:encoded>
  </item>
  <item>
    <title>Using Bonjour for iPhone/desktop application sync</title>
    <link>https://shrdlu.ch/using-bonjour-for-iphonedesktop-application-sync/</link>
    <guid isPermaLink="true">https://shrdlu.ch/using-bonjour-for-iphonedesktop-application-sync/</guid>
    <pubDate>Mon, 14 Jul 2008 13:58:08 -0000</pubDate>
    <content:encoded>&lt;p&gt;Many Cocoa developers might want to port their application(s) to the iPhone. I&#39;m one of these developers and the first problem I ran into was how to sync my desktop application&#39;s data with it&#39;s iPhone pendant. Some applications like OmniFocus use MobileMe or any WebDav server for synchronisation. Unfortunatly this is not an option for me because I don&#39;t want my users to have a MobileMe account or a Server just to sync with my app.&lt;/p&gt;
&lt;p&gt;My solution uses Bonjour to synchronize my app&#39;s data to the iPhone via the network. You can download &lt;a href=&#34;iphone-sync-demo.zip&#34;&gt; this demo project&lt;/a&gt; which contains a proof of concept version of my solution. The demo project consists of two XCode Projects. One desktop app and it&#39;s iPhone pendant.&lt;/p&gt;
&lt;p&gt;The idea is pretty simple: The desktop application needs to share it&#39;s data with the iPhone app via the network. Therefore the iPhone app creates a sync service and publishes it using the Bonjour technology. This way, the desktop application &#34;sees&#34; all iPhones (which are running the sync service) in the local network and offers the user a list from which he can choose the iPhone to sync with.&lt;br /&gt;
The application&#39;s data is then transfered onto the iPhone where it is saved as a file. The iPhone app can now work with this data.&lt;/p&gt;
&lt;p&gt;As I&#39;m short of time at the moment I could only implement this basic solution yet but I&#39;m sure I will extend it as soon as I&#39;ll find the time.&lt;br /&gt;
In a real world scenario the synchronization process might be a bit more complex. In most cases you may want to import your iPone app&#39;s data into your desktop app and vice versa. For this I&#39;d suggest to put the whole sync logic into your desktop app and perform something like this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Fetch the data from the iPhone&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Check it against your desktop app&#39;s data&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Resolve conflicts if they exist&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Import the data into your desktop app&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Put the whole data back to the iPhone&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;u&gt;&lt;strong&gt;Most Important: Security&lt;/strong&gt;&lt;/u&gt;&lt;br /&gt;
Whenever you deal with network services you &lt;strong&gt;have to&lt;/strong&gt; keep security in mind. When you start a network service on your iPhone it might be a potential security risk, since it opens a &#34;door&#34; to your applications data and everyone in the local network may be able to download this data.&lt;/p&gt;
&lt;p&gt;So you may want to create some kind of pairing or authentication protocol as well as encryption for your sync service. This means that when the app syncs for the very first time the user must enter some &#34;secret&#34; which identifies the the iPhone whic the user wants to sync with. Of course this mechanism becomes useless when you use an unencrypted protocol so you should think about encryption too.&lt;br /&gt;
Besides, you shoud ensure that the sync service is only stated when it is really needed. E.g. stop the service when the user swithes to some view other than the sync view, etc.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br /&gt;
Since the iPhone supports Bonjour, it could be used to sync data with any desktop application.&lt;br /&gt;
A full featured example project resides on your HD in /Developer/Examples/Foundation/PictureSharing and /Developer/Examples/Foundation/PictureSharingBrowser. This is where I took some code from :).&lt;/p&gt;
&lt;p&gt;Since I&#39;ve never held a real iPhone in my hands I only tried the example Project with the simulator. It would be nice to see if it works on real hardware. So, if you have tried it, please drop me a line.&lt;/p&gt;</content:encoded>
  </item>
  <item>
    <title>Ojective-C dot notation</title>
    <link>https://shrdlu.ch/ojective-c-dot-notation/</link>
    <guid isPermaLink="true">https://shrdlu.ch/ojective-c-dot-notation/</guid>
    <pubDate>Sun, 13 Jul 2008 10:53:03 -0000</pubDate>
    <content:encoded>&lt;p&gt;&lt;a href=&#34;http://www.cimgf.com/2008/07/08/a-case-against-dot-syntax/&#34;&gt;This&lt;/a&gt; blog post by Marcus Zarra made me happy. Now I know that I&#39;m not the only person who dislikes the dot notation which has been introduced in Objective-C 2.0.&lt;br /&gt;
The &#34;Properties&#34; feature is great, since it takes a lot of work writing accessor methods away from the developer. But accessing your object members sing the dot syntax makes your code ugly and cofusing.&lt;/p&gt;
&lt;p&gt;Ok, what shall I say? Marcus&#39; post says it all ...&lt;/p&gt;</content:encoded>
  </item>
  <item>
    <title>simpleTAN translated into english</title>
    <link>https://shrdlu.ch/simpletan-translated-into-english/</link>
    <guid isPermaLink="true">https://shrdlu.ch/simpletan-translated-into-english/</guid>
    <pubDate>Sat, 12 Jul 2008 14:43:35 -0000</pubDate>
    <content:encoded>&lt;p&gt;Did I mention that &lt;a href=&#34;&#34;&gt;s~~impleTAN~~&lt;/a&gt; is available in english? At the moment we are working on translating the website but it seems to take us longer than we thought. But if you want, you can give the app a try. A short description is available via this recent &lt;a href=&#34;/?p=12&#34;&gt;Blog Post&lt;/a&gt;. Enjoy using it :).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; simpleTAN isn&#39;t available anymore. The project has been closed. If you are interested in it give me a shout and I&#39;ll send you a copy. But I&#39;m pretty sure it won&#39;t run on OS X &amp;gt;= 10.5.7&lt;/p&gt;</content:encoded>
  </item>
  <item>
    <title>Relaunch an application</title>
    <link>https://shrdlu.ch/relaunch-an-application/</link>
    <guid isPermaLink="true">https://shrdlu.ch/relaunch-an-application/</guid>
    <pubDate>Wed, 02 Jul 2008 00:23:00 -0000</pubDate>
    <content:encoded>&lt;p&gt;Some tasks, e.g. restoring an application&#39;s data files from a backup should be performed while the application is not running to make sure there won&#39;t be any concurrent access to the files. A desirable behaviour would be: Quit the application, perform the work and finally relaunch the application - just as Sparkle does when installing an update.&lt;/p&gt;
&lt;p&gt;I&#39;ve created a simple but well-working solution for that problem. My solution is using a small helper application which performes the work which has to be done while the main application is not running and relaunches it afterwards. You can download the &lt;a href=&#34;relaunchexample.zip&#34;&gt;sample project&lt;/a&gt; to try it out by yourself.&lt;/p&gt;
&lt;p&gt;The RelaunchHelper is just an ordinary binary which has to be launched by your application just before it terminates itself. Of course, you can pass arguments to the RelaunchHelper. In the example project the path to the main application&#39;s bundle is the sole argument. After invoking the helper, your application should terminate itself and let te helper take over.&lt;br /&gt;
I let the helper app sleep for a few seconds befor it relaunches the application to ensure, all files opened by the main application (in this example this is not an issue) are properly closed.&lt;/p&gt;
&lt;p&gt;These are the steps you have to follow to create a project:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Create a target for the helper&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add all needed source files to that target&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Make that target a direct dependency of your main app&#39;s target to make sure the helper is also build when you build your main app&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a Copy Files build phase for your main app&#39;s target and add the helper to it. This is necessary to make the helper binary appear in your app&#39;s bundle&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Build and go :)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So, that&#39;s my solution to the relaunch issue. Maye it&#39;s not the most elegant way to do this. If you have a better solution, let me know. I really appreciate any comment.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt;&lt;br /&gt;
A much better way to implement a relaunch helper has been provided by Cédric Luthi in his Blog &lt;a href=&#34;http://0xced.blogspot.com/2006/06/relaunch-your-cocoa-application-by.html&#34;&gt;post&lt;/a&gt;.&lt;br /&gt;
Please check it out.&lt;/p&gt;</content:encoded>
  </item>
  <item>
    <title>Synchronizing the content of multiple NSArrayControllers</title>
    <link>https://shrdlu.ch/synchronizing-the-content-of-multiple-nsarraycontroller/</link>
    <guid isPermaLink="true">https://shrdlu.ch/synchronizing-the-content-of-multiple-nsarraycontroller/</guid>
    <pubDate>Mon, 30 Jun 2008 13:17:01 -0000</pubDate>
    <content:encoded>&lt;p&gt;As an application grows and it&#39;s UI becomes more complex, you definetly want to split the UI into multiple views and hold each of it in a seperate Nib File. This makes your project a lot more cleaner and helps you to keep overview.&lt;/p&gt;
&lt;p&gt;If you&#39;re using Core Data and you want to access your entities from all of your views you need to put an Array Controller in each of your Nib. But now you&#39;re running into the problem of synchronizing the contents of your Array Controllers since you have to provide the complete application data to all the views in which you need it. Fortunatly Cocoa Bindings help you to solve this issue quite elegantly.&lt;/p&gt;
&lt;p&gt;Download this &lt;a href=&#34;coredatamultipleviewstest.zip&#34;&gt;sample project&lt;/a&gt; which is an excerpt of a project I&#39;m currently working on.&lt;/p&gt;
&lt;p&gt;Now, let me explain what this project does in general: Basically you need some&lt;/p&gt;
&lt;p&gt;&#34;&lt;strong&gt;Master Array Controller&lt;/strong&gt;&#34; which is bound to your applications ManagedObjectContext and actually holds your application&#39; data. Then you need to bind the &lt;strong&gt;arrangedObjects&lt;/strong&gt; key of the Array Controller(s) which you want to synchronize with the Master Controller to the Master Controllers &lt;strong&gt;contentArray&lt;/strong&gt;. Then, you need to bind the &lt;strong&gt;managedObjectContext&lt;/strong&gt; of your Slave Controller(s) to the app delegate&#39;s managedObjectContext. That&#39;s it! Here&#39;s some code which illustrates this process:&lt;/p&gt;
&lt;p&gt;`&lt;/p&gt;
&lt;div class=&#34;codehilite&#34;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[[(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;MainWindowController&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)[&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;windowController&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;arrayControllerMaster&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;bind&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;contentArray&#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;toObject&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;slaveArrayController&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;withKeyPath&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;arrangedObjects&#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;options&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;nil&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;slaveArrayController&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;bind&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;managedObjectContext&#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;toObject&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NSApp&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;delegate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;withKeyPath&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;managedObjectContext&#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;options&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;nil&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;`&lt;br /&gt;
This example assumes, that the Master Controller is accessible in some way. In my example, I put it in the MainWindowController class and created a read-only accessor method. Take a look at the sample project to see what I mean.&lt;/p&gt;
&lt;p&gt;Conclusion:&lt;br /&gt;
As you can see, Cocoa Bindings enable you to synchronize the ArrayController of your application in a very easy manner. This helps you to keep your Nib Files and controller classes clean and well arranged.&lt;/p&gt;</content:encoded>
  </item>
  <item>
    <title>simpleTAN Beta Announcement</title>
    <link>https://shrdlu.ch/simpletan-beta-announcement/</link>
    <guid isPermaLink="true">https://shrdlu.ch/simpletan-beta-announcement/</guid>
    <pubDate>Mon, 09 Jun 2008 12:00:20 -0000</pubDate>
    <content:encoded>&lt;p&gt;The work on simpleTAN is coming to a close. Today I can proudly announce that the simpleTAN Beta is available for &lt;a href=&#34;&#34;&gt;~~download~~&lt;/a&gt;. simpleTAN is a TAN management application for MAC OS X focusing on security and usability.&lt;br /&gt;
You can comfortably enter your TANs and carry them with you securcely encrypted using the AES256 standard. When you need a TAN to perform a transfer just enter your passphrase and the TAN will be available instantly. You can also store the ammount and the reason for payment of every transfer. It&#39;s easy, give it a try ...&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; simpleTAN isn&#39;t available anymore. The project has been closed. If you are interested in it give me a shout and I&#39;ll send you a copy. But I&#39;m pretty sure it won&#39;t run on OS X &amp;gt;= 10.5.7&lt;/p&gt;</content:encoded>
  </item>
  <item>
    <title>Debugging BAD_ACCESS with NSZombieEnabled</title>
    <link>https://shrdlu.ch/debugging-bad_access-with-nszombieenabled/</link>
    <guid isPermaLink="true">https://shrdlu.ch/debugging-bad_access-with-nszombieenabled/</guid>
    <pubDate>Fri, 04 Apr 2008 09:02:52 -0000</pubDate>
    <content:encoded>&lt;p&gt;Everyone who had to debug a segmentation fault within an application, knows, how tricky it can be to detect such a bug. The reason for that is, that in most cases the crash doesn&#39;t occur in the line of code where the actual bug is. Instead your application crashes somewhere else, usually in some piece of code which doesn&#39;t have anything to do with the code that contains the bug.&lt;/p&gt;
&lt;p&gt;Fortunately, Cocoa offers a cool feature which greatly enhances your capabilities to debug such situations. It is an environment variable which is called &lt;a href=&#34;http://www.cocoadev.com/index.pl?NSZombieEnabled&#34;&gt;NSZombieEnabled&lt;/a&gt;. When set to YES,this variable causes Cocoa actually not to release an object after it has received a release message. Instead Cocoa just &#34;remembers&#34; that the object has received the release message&lt;br /&gt;
and on any subsequent messege sent to this object, a log message&lt;br /&gt;
is pribted to the console and &lt;a href=&#34;http://en.wikipedia.org/wiki/SIGTRAP&#34;&gt;SIGTRAP&lt;/a&gt; is thrown. The debugger immediately interrupts your application when you try to access an invalid object. A backtrace shows you the exact line of code which caused the &lt;strong&gt;BAD_ACCES&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;To enable NSZombieEnabled simple open the Info panel of your application executable within XCode and set it to &lt;strong&gt;YES&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;enable_zombie.png&#34;&gt;&lt;img alt=&#34;How to enable NSZombieEnabled&#34; class=&#34;alignnone&#34; src=&#34;enable_zombie.png&#34; width=&#34;294&#34; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now write some lines of code to see how it works:&lt;/p&gt;
&lt;div class=&#34;codehilite&#34;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&#34;bp&#34;&gt;NSDate&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSDate&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;NSLog&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;Date: %@&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;cm&#34;&gt;/* good access */&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;release&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;NSLog&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;Date: %@&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;cm&#34;&gt;/* bad access, causes a crash */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now, if you run this code inside the debugger, your application will stop when the bad access occurs and with a backtrace you can easily find the line of code which caused it.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;crash_dump.png&#34;&gt;&lt;img alt=&#34;See exactly where it crashed&#34; class=&#34;alignnone&#34; src=&#34;crash_dump.png&#34; width=&#34;300&#34; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Cool, isn&#39;t it?&lt;br /&gt;
Remember to turn of NSZombieEnabled after you have finished the debugging.&lt;/p&gt;</content:encoded>
  </item>
  <item>
    <title>Introducing simpleTAN</title>
    <link>https://shrdlu.ch/introducing-simpletan/</link>
    <guid isPermaLink="true">https://shrdlu.ch/introducing-simpletan/</guid>
    <pubDate>Tue, 01 Apr 2008 23:10:44 -0000</pubDate>
    <content:encoded>&lt;p&gt;SimpleTAN, the application I am working on at &lt;a href=&#34;http://www.bidli.de&#34;&gt;Bidli Software&lt;/a&gt; is a&lt;br /&gt;
TAN management tool for Mac OS X. If you&#39;re doing online banking&lt;br /&gt;
with PIN/TAN and use tools like GPG or aespipe to securely take&lt;br /&gt;
your TAN&#39;s with you on your laptop or simply store them on your&lt;br /&gt;
mac to have them right at hand when you need them, then you&#39;ll&lt;br /&gt;
love simpleTAN. It lets you easily enter your TAN numbers and you&lt;br /&gt;
can retrieve them just by entering your password. After you have&lt;br /&gt;
used the TAN, you can mark it as used (and optionally store the&lt;br /&gt;
amount and purpose of your transaction with it). So you can easily&lt;br /&gt;
track which TAN you have used  when and for what transaction. Of&lt;br /&gt;
course, all your TAN&#39;s are stored  encrypted (using aes256, which is&lt;br /&gt;
also used by Apple&#39;s FileVault) in the database. SimpleTAN focuses&lt;br /&gt;
on both, security and ease of use. It will be shipped soon. Stay tuned&lt;br /&gt;
to find out more ...&lt;/p&gt;</content:encoded>
  </item>
  <item>
    <title>Core Data Encryption</title>
    <link>https://shrdlu.ch/core-data-encryption/</link>
    <guid isPermaLink="true">https://shrdlu.ch/core-data-encryption/</guid>
    <pubDate>Sat, 29 Mar 2008 23:08:30 -0000</pubDate>
    <content:encoded>&lt;p&gt;I recently wondered how to encrypt the attributes of a Core Data&lt;br /&gt;
application. The encryption should be transparent to the application,&lt;br /&gt;
which means the entity objects should do all of the encryption/&lt;br /&gt;
decryption work and the rest of the application doesn&#39;t even know&lt;br /&gt;
that there is something happening. This way, you can continue using&lt;br /&gt;
bindings with Interface Builder and all the other convenient stuff&lt;br /&gt;
which Core Data offers without worrying about your encryption/&lt;br /&gt;
decryption.&lt;/p&gt;
&lt;p&gt;You can download the &lt;a href=&#34;encryption-demo.zip&#34;&gt;Demo Project&lt;/a&gt; (created with Xcode 3.1 beta).&lt;br /&gt;
Note: The Demo Project includes the SSCrypto Framework. Please&lt;br /&gt;
respect it&#39;s copyright.&lt;/p&gt;
&lt;p&gt;But how do you actually encrypt stuff using Cocoa? Obviously Cocoa&lt;br /&gt;
doesn&#39;t offer any suitable objects - but Mac OS X does. Mac OS X&lt;br /&gt;
ships with OpenSSL, a powerful and robust tool which offers many&lt;br /&gt;
important cryptographic functions. OpenSSL is also a full-featured&lt;br /&gt;
library (libcrypto). This library is exactly what we need to perform&lt;br /&gt;
encryption within a Core Data application. If you take a closer look&lt;br /&gt;
at the OpenSSL library functions, you may find them a bit difficult&lt;br /&gt;
to use (especially if you have only a basic knowledge of all the&lt;br /&gt;
cryptographic stuff), but furtunatly there is &lt;a href=&#34;http://septicus.com/products/opensource/&#34;&gt;SSCrypto&lt;/a&gt; - an easy-to-use&lt;br /&gt;
Cocoa Framework wich wraps around OpenSSL and does all the&lt;br /&gt;
tricky stuff for us.&lt;/p&gt;
&lt;p&gt;This sounds pretty good, does it? So let&#39;s see, how to put all this&lt;br /&gt;
together in a Core Data application.&lt;/p&gt;
&lt;p&gt;Core Data doesn&#39;t support encryption as well. If you&#39;re coding for&lt;br /&gt;
Leopard only, maybe you can use an &lt;a href=&#34;http://developer.apple.com/documentation/Cocoa/Conceptual/AtomicStore_Concepts/Articles/asFundamentals.html#//apple_ref/doc/uid/TP40004526&#34;&gt;Atomic Store&lt;/a&gt; to encrypt/decrypt&lt;br /&gt;
your whole Persistent Store (I haven&#39;t tried this yet, since my apps&lt;br /&gt;
have to be Tiger compatible).&lt;/p&gt;
&lt;p&gt;Instead we will use &lt;a href=&#34;http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdNSAttributes.html&#34;&gt;Transient Attributes&lt;/a&gt; to transparently encrypt the attributes of our entities.&lt;br /&gt;
Each of the attributes we want to encrypt must be transient and&lt;br /&gt;
must have a corresponding &#34;Data Attribute&#34; of type &#34;Binary Data&#34;&lt;br /&gt;
which is persistent and actually holds the encrypted data. In XCode&lt;br /&gt;
your model could look like this:&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;model.png&#34;&gt;&lt;img alt=&#34;&#34; class=&#34;alignnone&#34; src=&#34;model.png&#34; width=&#34;300&#34; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now we need to create a NSManagedObject subclass which represents&lt;br /&gt;
the entity. If you create this class with the XCode wizard, don&#39;t let it&lt;br /&gt;
create Objective-C 2.0 Properties since we need to add custom&lt;br /&gt;
accessor methods. The class interface looks as follows:&lt;/p&gt;
&lt;div class=&#34;codehilite&#34;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&#34;k&#34;&gt;@interface&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;Item&lt;/span&gt; :  &lt;span class=&#34;bp&#34;&gt;NSManagedObject&lt;/span&gt;  
&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;

&lt;span class=&#34;p&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSString&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;itemName&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;void&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;setItemName:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSString&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;

&lt;span class=&#34;p&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSData&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;creationDateData&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;void&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;setCreationDateData:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSData&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;

&lt;span class=&#34;p&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSData&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;itemNameData&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;void&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;setItemNameData:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSData&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;

&lt;span class=&#34;p&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSNumber&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;itemId&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;void&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;setItemId:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSNumber&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;

&lt;span class=&#34;p&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSData&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;itemIdData&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;void&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;setItemIdData:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSData&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;

&lt;span class=&#34;p&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSDate&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;creationDate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;void&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;setCreationDate:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSDate&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;

&lt;span class=&#34;k&#34;&gt;@end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We don&#39;t have to touch the accessors for the &#34;Data Attributs&#34; but the&lt;br /&gt;
accessors for the transient attributes need to be customized in order&lt;br /&gt;
to perform encryption/decryption.&lt;br /&gt;
Let&#39;s take a look at &lt;strong&gt;-(NSString *)itemName&lt;/strong&gt; which performs&lt;br /&gt;
decryption of the attribute &#34;itemName&#34;:&lt;/p&gt;
&lt;div class=&#34;codehilite&#34;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&#34;p&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSString&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;itemName&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSString&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tmpValue&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;willAccessValueForKey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;itemName&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tmpValue&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;primitiveValueForKey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;itemName&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;didAccessValueForKey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;itemName&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tmpValue&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;||&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tmpValue&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;isEqualToString&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSData&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;encryptedData&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;valueForKey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;itemNameData&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;cm&#34;&gt;/* if there are any encrypted data, decrypt it */&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;encryptedData&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;cm&#34;&gt;/* init SSCrypto with the stored key from the PasswordController */&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;SSCrypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;crypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;SSCrypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alloc&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;initWithSymmetricKey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;PasswordController&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sharedInstance&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;keyData&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]];&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;crypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;setCipherText&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSKeyedUnarchiver&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;unarchiveObjectWithData&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;encryptedData&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]];&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSData&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;decryptedData&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;crypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;decrypt&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;aes256&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;cm&#34;&gt;/* some debugging output. maybe useful. you can wrap them with #ifdef/#endif directives to enable them only in debug configuration */&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NSLog&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;Using symmetric key: %@&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;       &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;crypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;symmetricKey&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;hexval&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]);&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NSLog&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;Archived itemName: %@&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;         &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;encryptedData&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;hexval&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]);&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NSLog&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;Encrypted itemName: %@&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;crypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;cipherTextAsData&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;hexval&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]);&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NSLog&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;Decrypted itemName: %@&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;crypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;clearTextAsString&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]);&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tmpValue&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[[&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSString&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alloc&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;initWithData&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;decryptedData&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;encoding&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NSUTF8StringEncoding&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;setPrimitiveValue&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tmpValue&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;forKey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;itemName&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;crypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;release&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;else&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;cm&#34;&gt;/* insert the defalt value here */&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tmpValue&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;Default Value&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;            &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;setItemName&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tmpValue&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;        &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;return&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tmpValue&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Basically, this method loads the encrypted data (if it exists) and&lt;br /&gt;
decrypts it. The decrypted data is stored in the primitive value so&lt;br /&gt;
it doesn&#39;t need to be decrypted each time it is accessed - only when&lt;br /&gt;
it is read for the first time. If there is no encrypted data (a new&lt;br /&gt;
entity is inserted), then the default value is used.&lt;/p&gt;
&lt;p&gt;The set accessor for the &lt;strong&gt;itemName&lt;/strong&gt; attribute works in a&lt;br /&gt;
similar way. It performs the following steps:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If the new value equals the old one, return. This avoids any&lt;br /&gt;
unnecessary encryption which dramatically reduces cpu load, since&lt;br /&gt;
Core Data acesses the attributes quite heavily&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Store the new value in the primitive value&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Encrypt the new value and store it in the &#34;Data Attribute&#34;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here&#39;s the code:&lt;/p&gt;
&lt;div class=&#34;codehilite&#34;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class=&#34;p&#34;&gt;-&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;void&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;setItemName:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSString&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;nv&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSString&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tmpValue&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;willAccessValueForKey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;itemName&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tmpValue&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;primitiveValueForKey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;itemName&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;didAccessValueForKey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;itemName&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;cm&#34;&gt;/* if the new value is equal to the old value, return. this improves the performance a lot, since core data&lt;/span&gt;
&lt;span class=&#34;cm&#34;&gt;     accesses the attributes quite heavily and encrypting them would stress the cpu when it&#39;s not really necessary*/&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;if&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;([&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tmpValue&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;isEqualToString&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;])&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;return&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;willChangeValueForKey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;itemName&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;setPrimitiveValue&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;forKey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;itemName&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;didChangeValueForKey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;itemName&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;SSCrypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;crypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;SSCrypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;alloc&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;initWithSymmetricKey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;PasswordController&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sharedInstance&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;keyData&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]];&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;crypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;setClearTextWithData&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dataUsingEncoding&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NSUTF8StringEncoding&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]];&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSData&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;encryptedData&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;crypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;encrypt&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;aes256&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NSLog&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;Encrypting itemName: %@&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;               &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NSLog&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;Encrypting itemName: %@ with key: %@&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;crypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;symmetricKey&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;hexval&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]);&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NSLog&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;Encrypted itemName: %@&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;encryptedData&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;hexval&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]);&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;NSLog&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;Archived itemName: %@&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;                 &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[[&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSKeyedArchiver&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;archivedDataWithRootObject&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;encryptedData&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;hexval&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]);&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;cm&#34;&gt;/* archiving the encrypted value ensures, that it can be saven as plain-text xml */&lt;/span&gt;
&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;setPrimitiveValue&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;NSKeyedArchiver&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;archivedDataWithRootObject&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;encryptedData&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;n&#34;&gt;forKey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;@&#34;itemNameData&#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;

&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;crypto&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;k&#34;&gt;release&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;];&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;       &lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In prinziple, this is how the encryption works. But what key is&lt;br /&gt;
used to encrypt the data and where does it come from? In our&lt;br /&gt;
example the key is entered by the user. I have created a class&lt;br /&gt;
called &lt;strong&gt;PasswordController&lt;/strong&gt; which stores the key data.&lt;br /&gt;
This class is designed to be a singleton because only one instance&lt;br /&gt;
of it is needed within the whole application.&lt;/p&gt;
&lt;p&gt;When the application is launched, I use the&lt;br /&gt;
&lt;strong&gt;-applicationDidFinishLaunching&lt;/strong&gt; method to request the&lt;br /&gt;
key from the user and store the data in the PasswordController.&lt;br /&gt;
When you take a look at the console, while you launch the app,&lt;br /&gt;
you will notice, that there is happening a lot of stuff &lt;strong&gt;before&lt;/strong&gt;&lt;br /&gt;
the user has entered the key. This is because Core Data accesses&lt;br /&gt;
the attributes right after the Nib-Files have been loaded. But the&lt;br /&gt;
&lt;strong&gt;-applicationDidFinishLaunching&lt;/strong&gt; method is called after that.&lt;br /&gt;
I haven&#39;t found any issues with this yet. If you find any problems,&lt;br /&gt;
please let me know.&lt;/p&gt;
&lt;p&gt;Another aspect I&#39;d like to mention is, that the demo application&lt;br /&gt;
cannot determine if the user has entered the wrong key. In that&lt;br /&gt;
case, the decryption simply does not work and any newly created&lt;br /&gt;
items are encrypted with the other key, which produces a&lt;br /&gt;
currupted Persistent Store (it&#39;s not really &#34;damaged&#34;, but unusable.&lt;br /&gt;
Try it, you&#39;ll see what I mean).&lt;/p&gt;
&lt;p&gt;This issue coud be addressed by including a digest (sha1, or&lt;br /&gt;
something) of the key in the Persistent Store and compare it each&lt;br /&gt;
time the user has entered the key. The Metadata Dictionary of the&lt;br /&gt;
persistent Store would be a good place to put it in. This is not yet&lt;br /&gt;
included in the demo application since I didn&#39;t find the time yet.&lt;br /&gt;
Maybe I will do it in some future version. Sorry for that!&lt;/p&gt;</content:encoded>
  </item>
</channel>
</rss>