Home
Search results “Createencryptor c example codes”
Encrypt and Decrypt Data with C# || E-Learning Portal
 
08:31
This tutorial will teach you how to encrypt and decrypt your data in c#. net. You can store this encrypted data to your database or a text file or wherever you want. You can easily encrypt your data and then decrypt it also and store it into file or where ever you want. Given down below is the code for encryption and decryption. /////////////////////////////////////////////////////////////////////////////////////// Code for Encryption: ////////////////////////////////////////////////////////////////////////////////////// public static string Encrypt(string clearText) { string EncryptionKey = "abc123"; byte[] clearBytes = Encoding.Unicode.GetBytes(clearText); using (Aes encryptor = Aes.Create()) { Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); encryptor.Key = pdb.GetBytes(32); encryptor.IV = pdb.GetBytes(16); using (MemoryStream ms = new MemoryStream()) { using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write)) { cs.Write(clearBytes, 0, clearBytes.Length); cs.Close(); } clearText = Convert.ToBase64String(ms.ToArray()); } } return clearText; } /////////////////////////////////////////////////////////////////////////////////////// Code for Decryption: ////////////////////////////////////////////////////////////////////////////////////// public static string Decrypt(string cipherText) { string EncryptionKey = "abc123"; cipherText = cipherText.Replace(" ", "+"); try { byte[] cipherBytes = Convert.FromBase64String(cipherText); using (Aes encryptor = Aes.Create()) { Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); encryptor.Key = pdb.GetBytes(32); encryptor.IV = pdb.GetBytes(16); using (MemoryStream ms = new MemoryStream()) { using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write)) { cs.Write(cipherBytes, 0, cipherBytes.Length); cs.Close(); } cipherText = Encoding.Unicode.GetString(ms.ToArray()); } } } catch (Exception ex) { } return cipherText; } /////////////////////////////////////////////////////////////////////////////////////////////// If you have any questions and comments, write down them in comments below or mail me at [email protected]
Views: 2678 E-Learning Portal
CPS Popular Data Encryption Using C Sharp Dot net(Meher Chaitanya Bandaru)
 
11:03
CPS Popular Data Encryption & Decryption using C Sharp (C#) Using the Name-Space System.Security.Cryptography ================================ Code: -------------- public string Encrypt(string input) { string key = "sblw-3hn8-sqoy19"; byte[] inputArray = UTF8Encoding.UTF8.GetBytes(input); TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider(); tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key); tripleDES.Mode = CipherMode.ECB; tripleDES.Padding = PaddingMode.PKCS7; ICryptoTransform cTransform = tripleDES.CreateEncryptor(); byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length); tripleDES.Clear(); return Convert.ToBase64String(resultArray, 0, resultArray.Length); } public string Decrypt(string input) { string key = "sblw-3hn8-sqoy19"; byte[] inputArray = Convert.FromBase64String(input); TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider(); tripleDES.Key = UTF8Encoding.UTF8.GetBytes(key); tripleDES.Mode = CipherMode.ECB; tripleDES.Padding = PaddingMode.PKCS7; ICryptoTransform cTransform = tripleDES.CreateDecryptor(); byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length); tripleDES.Clear(); return UTF8Encoding.UTF8.GetString(resultArray); }
Views: 201 Cool Programmers
تشفير كلمة المرور
 
01:24
Public Function Encrypt(ByVal text As String, ByVal key As String) As String Try Dim crp As New TripleDESCryptoServiceProvider Dim uEncode As New UnicodeEncoding Dim bytPlainText() As Byte = uEncode.GetBytes(text) Dim stmCipherText As New MemoryStream Dim slt() As Byte = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} Dim pdb As New Rfc2898DeriveBytes(key, slt) Dim bytDerivedKey() As Byte = pdb.GetBytes(24) crp.Key = bytDerivedKey crp.IV = pdb.GetBytes(8) Dim csEncrypted As New CryptoStream(stmCipherText, crp.CreateEncryptor(), CryptoStreamMode.Write) csEncrypted.Write(bytPlainText, 0, bytPlainText.Length) csEncrypted.FlushFinalBlock() Return Convert.ToBase64String(stmCipherText.ToArray()) Catch ex As Exception Throw End Try End Function
Views: 100 Saud Sharary