Windows Phone encrypts and decrypts files

Source: Internet
Author: User
 Private   Void Decryption ( String  Mima) {isolatedstoragefilestream = New Isolatedstoragefilestream ( "  Aaa.zip Encryption  " , Filemode. Open, fileaccess. read, This  . Storgfile); isolatedstoragefilestream stream2 = New Isolatedstoragefilestream ( " Aaa.zip  " + "  Decryption  " , Filemode. openorcreate, fileaccess. Write, This  . Storgfile );  Byte [] Buffer = New   Byte [ 100  ];  Long Num = 0l  ; Long Length = Stream. length;  String Password = Mima;  String S = "  Saltvalue  "  ;  Byte [] Salt = Encoding. utf8.getbytes (s); rfc2898derivebytes bytes = New  Rfc2898derivebytes (password, salt ); This . AES. keysize = This . AES. legalkeysizes [ 0  ]. Maxsize;  This . AES. blocksize = This . AES. legalblocksizes [ 0  ]. Maxsize;  This . AES. Key = bytes. getbytes ( This . AES. keysize/ 8  );  This . AES. IV = bytes. getbytes (This . AES. blocksize/ 8  ); Cryptostream stream3 = New Cryptostream (stream2, This . AES. createdecryptor ( This . AES. Key, This  . AES. IV), cryptostreammode. Write );  Try  {  Try  {  While (Num < Length ){  Int Count = stream. Read (buffer, 0 , 100  ); Stream3.write (buffer,  0  , Count); num + = Count;} stream3.close ();}  Catch  {MessageBox. Show (  " Incorrect password! Cannot decrypt!  "  );}}  Finally  {Stream. Close (); stream2.close ();}} 
  Private   Void Encryption ( String  Mima ){  //  Try  {Isolatedstoragefilestream stream = New Isolatedstoragefilestream ( "  Aaa.zip  " , Filemode. Open, fileaccess. read, This  . Storgfile); isolatedstoragefilestream stream2 = New Isolatedstoragefilestream ( "  Aaa.zip  " + "  Encryption  " , Filemode. openorcreate, fileaccess. Write, This . Storgfile );  Byte [] Buffer = New   Byte [ 100  ];  Long Num = 0l  ;  Long Length = Stream. length;  String Password = Mima;  String S ="  Saltvalue  "  ;  Byte [] Salt = Encoding. utf8.getbytes (s); rfc2898derivebytes bytes = New  Rfc2898derivebytes (password, salt );  This . AES. keysize = This . AES. legalkeysizes [ 0  ]. Maxsize;  This . AES. blocksize =This . AES. legalblocksizes [ 0  ]. Maxsize;  This . AES. Key = bytes. getbytes ( This . AES. keysize/ 8  );  This . AES. IV = bytes. getbytes ( This . AES. blocksize/ 8  ); Cryptostream stream3 = New Cryptostream (stream2,This . AES. createencryptor ( This . AES. Key, This  . AES. IV), cryptostreammode. Write );  While (Num < Length ){  Int Count = stream. Read (buffer, 0 , 100  ); Stream3.write (buffer,  0  , Count); num + =Count;} MessageBox. Show (  "  File encrypted!  "  ); Stream3.close (); stream. Close (); stream2.close ();}  //  Catch  //  {  //  MessageBox. Show ("the file is not placed in the specified isolatedstore directory! ");  //  } }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.