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! "); // } }