The video of the company learning platform downloaded from the app needs to be encrypted
Refer to some of the wording for finding data
Wrote the AES encryption method.
Record to prevent forgetting
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Security.Cryptography;usingSystem.Text;usingSystem.Threading.Tasks;namespaceconsoleapplication1{classClass1 {Private Const stringSKey ="_?73^?dvt3st5har3"; Private Const stringSaltkey ="[Email Protected]&kt3st5har3ey"; Private Const intiterations =1042;//recommendation is >= Static byte[] GetBytes (stringstr) { varbytes =New byte[Str. Length *sizeof(Char)]; Buffer.blockcopy (str. ToCharArray (),0, Bytes,0, Bytes. Length); returnbytes; } Static stringGenerateKey () {//Create An instance of Symetric algorithm. Key and IV is generated automatically.DESCryptoServiceProvider Descrypto =(DESCryptoServiceProvider) descryptoserviceprovider.create (); //Use the automatically generated key for encryption. returnASCIIEncoding.ASCII.GetString (Descrypto.key); } Public Static voidEncryptFile (stringSrcfilename,stringdestfilename) { varAES =Newaesmanaged (); Aes. BlockSize= -; Aes. KeySize= the; varSalt =GetBytes (Saltkey); varKey =Newrfc2898derivebytes (SKey, salt, iterations); Aes. Key= key. GetBytes (AES. KeySize/8); Aes.iv= key. GetBytes (AES. BlockSize/8); Aes. Mode=CIPHERMODE.CBC; ICryptoTransform Transform=AES. CreateEncryptor (AES. Key, AES.IV); using(varDest =NewFileStream (destFileName, FileMode.CreateNew, FileAccess.Write, Fileshare.none)) { using(varCryptoStream =NewCryptoStream (dest, Transform, CryptoStreamMode.Write)) { using(varSource =NewFileStream (Srcfilename, FileMode.Open, FileAccess.Read, FileShare.Read)) {source. CopyTo (CryptoStream); } } } } Public Static voidDecryptFile (stringSrcfilename,stringdestfilename) { varAES =Newaesmanaged (); Aes. BlockSize= -; Aes. KeySize= the; varSalt =GetBytes (Saltkey); varKey =Newrfc2898derivebytes (SKey, salt, iterations); Aes. Key= key. GetBytes (AES. KeySize/8); Aes.iv= key. GetBytes (AES. BlockSize/8); Aes. Mode=CIPHERMODE.CBC; ICryptoTransform Transform=AES. CreateDecryptor (AES. Key, AES.IV); using(varDest =NewFileStream (destFileName, FileMode.CreateNew, FileAccess.Write, Fileshare.none)) { using(varCryptoStream =NewCryptoStream (dest, Transform, CryptoStreamMode.Write)) { Try { using(varSource =NewFileStream (Srcfilename, FileMode.Open, FileAccess.Read, FileShare.Read)) {source. CopyTo (CryptoStream); } } Catch(Cryptographicexception exception) {Throw NewApplicationException ("decryption failed.", exception); } } } } }}
Run
Static voidMain (string[] args) { //class1.encryptfile (@ "C:\kc_Page_2.mp4", @ "C:\kc_Page_3.mp4"); //class1.decryptfile (@ "C:\kc_Page_3.mp4", @ "C:\kc_Page_4.mp4");Class1.encryptfile (@"C:\1.docx",@"C:\2.docx"); Class1.decryptfile (@"C:\2.docx",@"C:\3.docx"); }
. NET AES encrypted video and other files