#setlinebreak(on);
[[WP TIPS に戻る>wp7/tips]]

*データを暗号化する [#u3cae9e8]
Windows Phone7 の Silverlight で使用できる暗号化アルゴリズムは、Triple DES と AES を使用することが出来、文字列やバイナリ列などを暗号化してファイルに保存することが出来ます。

**ProtectedData クラスを使用して Triple DES で暗号化する [#mf699f6d]
System.Security.Cryptography.ProtectedData クラスを使用することで、簡単にバイト列の暗号化を行う事が出来ます。

 using System.Security.Cryptography;
 
 // 暗号化する文字列
 string plaintext = "hello";
 
 // 暗号化
 byte[] protectedBytes = ProtectedData.Protect(Encoding.UTF8.GetBytes(plaintext), null);
 
 // 復号化
 byte[] unprotectedBytes = ProtectedData.Unprotect(protectedBytes, null);
 
 // 文字列を取得する
 string text = Encoding.UTF8.GetString(unprotectedBytes, 0, unprotectedBytes.Length);

ファイルに

 using (var store = IsolatedStorageFile.GetUserStoreForApplication())
 {
     using (var stream = new IsolatedStorageFileStream(REG_INFO_FILE, FileMode.Open, FileAccess.Read, store))
     {
         using (var reader = new StreamReader(stream))
         {
             byte[] rawData = new byte[reader.Length];
             reader.Read(rawData, 0, Convert.ToInt16(byteStream.Length));
 
             byte[] safeData = ProtectedData.Unprotect(rawData, null);
          }
     }
 }


WP 7 Mango and ProtectedData – Reminder
http://www.nextbestgeek.com/2011/05/30/wp-7-mango-and-protecteddata-reminder/

Windows Phone 7 Mango リリースで IsolatedStorage に DPAPI を使用する
http://blogs.msdn.com/b/sharepoint_jp/archive/2011/08/30/windows-phone-7-mango-isolatedstorage-dpapi.aspx

Don’t forget to Encrypt your Windows Phone 7 Data
http://robtiffany.com/windows-phone-7/dont-forget-to-encrypt-your-windows-phone-7-data