To encrypt the PIN

   // Convert the PIN to a byte[].
byte[] PinByte = Encoding.UTF8.GetBytes(TBPin.Text); // Encrypt the PIN by using the Protect() method.
byte[] ProtectedPinByte = ProtectedData.Protect(PinByte, null); // Store the encrypted PIN in isolated storage.
this.WritePinToFile(ProtectedPinByte);

Write PIN to file

    // Create a file in the application's isolated storage.
IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream writestream = new IsolatedStorageFileStream(FilePath, System.IO.FileMode.Create, System.IO.FileAccess.Write, file); // Write pinData to the file.
Stream writer = new StreamWriter(writestream).BaseStream;
writer.Write(pinData, 0, pinData.Length);
writer.Close();
writestream.Close();

To decrypt the data

    // Retrieve the PIN from isolated storage.
byte[] ProtectedPinByte = this.ReadPinFromFile(); // Decrypt the PIN by using the Unprotect method.
byte[] PinByte = ProtectedData.Unprotect(ProtectedPinByte, null); // Convert the PIN from byte to string and display it in the text box.
TBPin.Text = Encoding.UTF8.GetString(PinByte, 0, PinByte.Length);

Read PIN from file

    // Access the file in the application's isolated storage.
IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream readstream = new IsolatedStorageFileStream(FilePath, System.IO.FileMode.Open, FileAccess.Read, file); // Read the PIN from the file.
Stream reader = new StreamReader(readstream).BaseStream;
byte[] pinArray = new byte[reader.Length]; reader.Read(pinArray, 0, pinArray.Length);
reader.Close();
readstream.Close(); return pinArray;

  

 

Windows Phone Data Protection的更多相关文章

  1. ASP.NET Core 数据保护(Data Protection 集群场景)【下】

    前言 接[中篇],在有一些场景下,我们需要对 ASP.NET Core 的加密方法进行扩展,来适应我们的需求,这个时候就需要使用到了一些 Core 提供的高级的功能. 本文还列举了在集群场景下,有时候 ...

  2. ASP.NET Core 数据保护(Data Protection)【上】

    前言 上一篇博客记录了如何在 Kestrel 中使用 HTTPS(SSL), 也是我们目前项目中实际使用到的. 数据安全往往是开发人员很容易忽略的一个部分,包括我自己.近两年业内也出现了很多因为安全问 ...

  3. Asp.net core 学习笔记 ( Data protection )

    参考 : http://www.cnblogs.com/xishuai/p/aspnet-5-identity-part-one.html http://cnblogs.com/xishuai/p/a ...

  4. vSphere Data Protection – a new backup product included with vSphere 5.1

    August 27, 2012 By Vladan SEGET This new backup product replaces VMware Data Recovery, which has bee ...

  5. 实验室报告:VMware vSphere Data Protection

    dd Lab Reports VMware vSphere Data Protection Fast, Simple, and Agentless Deduplicated Virtual Machi ...

  6. ASP.NET Core 数据保护(Data Protection)【中】

    前言 上篇主要是对 ASP.NET Core 的 Data Protection 做了一个简单的介绍,本篇主要是介绍一下API及使用方法. API 接口 ASP.NET Core Data Prote ...

  7. iOS 开启data protection 的方法

    我这里说的data protection,指的是设备设置密码后,如果设备锁屏,并且当前解锁需要密码(有时可能因为自己的设定,导致会再几小时后才需要密码),这时应用程序处于加密状态,无法从外部读取.如果 ...

  8. Data Protection - how to manage expired key?(转载)

    问 According to ASP.NET Key Management: Deleting a key is truly destructive behavior, and consequentl ...

  9. 【VMware vSphere】vSphere Data Protection简介

    [前言] 还记得一月份左右的时候,万达这边的服务器突然宕机,导致所有的项目不得不停止不说,还损失掉了很多宝贵的数据.为了防止这种情况再次发生,所以近期研究了vSphere Data Protectio ...

随机推荐

  1. hdu 3709 数位dp

    数位dp,有了进一步的了解,模板也可以优化一下了 题意:找出区间内平衡数的个数,所谓的平衡数,就是以这个数字的某一位为支点,另外两边的数字大小乘以力矩之和相等,即为平衡数例如4139,以3为支点4*2 ...

  2. Sql Server 基础知识

    Sql Server 基础知识: http://blog.csdn.net/t6786780/article/details/4525652 Sql Server 语句大全: http://www.c ...

  3. 在Salesforce中进行Report和Dashboard的配置

    用Report和Dashboard去图形化比较不同Object的信息是一个十分普遍的需求,当然我们可以完全用Visual Page和Classes去自定义对应的Report和Dashboard的功能. ...

  4. 汇编学习(一)——win7 64位调出debug

    一.安装方法: 1.下载一个dosbox和win7 32位debug.exe,安装dosbox,打开页面 2. 将debug.exe放入磁盘根目录,这里以D盘为例.在dosbox中输入mount c ...

  5. Linux学习笔记(7)Linux常用命令之压缩解压命令

    (1)gzip gzip命令用于压缩文件,英文原意为GNU zip,所在路径/bin/gzip,其语法格式为: gzip [文件] 压缩后的文件格式为.gz. 例:将/etc目录下的services文 ...

  6. thinkphp数据表操作恐怖事件。

    1当使用thinkphp的where(array())时,如果里面的字段在数据库是没有的,则默认这个条件为1,这时就可能出现大批修改记录问题.如修改所有用户的密码.特别要注意的是,这里的表字段是区分大 ...

  7. poj1061 Exgcd

    #include<iostream> #include<cstdio> #include<algorithm> #include<cmath> usin ...

  8. HTTP基础07--认证

    何为认证 BASIC 认证 是从 HTTP/1.0 就定义的认证方式.即便是现在仍有一部分的网站会使用这种认证方式.是 Web 服务器与通信客户端之间进行的认证方式. 步骤 1: 当请求的资源需要 B ...

  9. Xamarin Android教程如何使用Xamarin开发Android应用

    Xamarin Android教程如何使用Xamarin开发Android应用 在了解了Xamarin和Andriod系统之后,下面我们需要了解一下如何使用这些工具和系统来开发我们的应用程序. And ...

  10. Swift3.0语言教程比较、判断字符串

    Swift3.0语言教程比较.判断字符串 Swift3.0语言教程比较.判断字符串,在一个程序中字符串很多时,常常会做的操作就是对这些字符串进行比较和判断.本小节将讲解这些内容. 1.不区分大小写比较 ...