Document decryption

xiaoxiao2021-03-06  84

Encryption: static String Encrypt (String pwd) {DESCryptoServiceProvider desc = new DESCryptoServiceProvider (); // des encrypting PasswordDeriveBytes db = new PasswordDeriveBytes (pwd, null); // generate keybyte [] key = db.GetBytes (8); MemoryStream MS = new memoryStream (); // Store encrypted data CRYPTOSTREAM CS = New CryptostReam (MS, Desc.CreateEncryptor (key, key), cryptostreammode.write; byte [] data = encoding. commicode.getbytes (PWD); / / Take the password bytes cs.write (data, 0, data.length); // to encrypt cs.flushfinalblock (); byte [] res = ms.toarray (); // Take the encrypted data return Encoding.Unicode.GetString (res); // switch to decrypt the returned string}: static string decrypt (string pwd, string data) {DESCryptoServiceProvider desc = new DESCryptoServiceProvider (); PasswordDeriveBytes db = new PasswordDeriveBytes (pwd, null); // generates keybyte [] key = db.GetBytes (8); MemoryStream ms = new MemoryStream (); // data after storing the decrypted CryptoStream cs = new CryptoStream (ms, desc.CreateDecryptor (key, key), CryptoStreamMode.Write ); byte [] databytes = encoding.unicode.getbytes (data); // Take the byte stream of encrypted data CS.Write (dataBytes, 0, Databytes.length); // Decrypt data cs.flushfinalblock (); byte [] res = ms.toarray (); return eNCoding.Unicode.getstring (res); // Return to decrypted data}

转载请注明原文地址:https://www.9cbs.com/read-124037.html

New Post(0)