Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Security.Cryptography;
- using System.IO;
- using System.text;
- namespace sirhC Coding.CodeLibrary
- {
- public class Utilitites
- {
- // Properties and fields.
- #region Properties and Fields.
- private static byte[] _bytes = ASCIIEndcoding.ASCII.GetBytes("ACLT2017");
- #endregion
- // Constructors.
- #region Constructors
- #endregion
- // public methods.
- #region Public Methods
- //<summary>
- //Encrypt a string.
- //</summary/>
- //<param mane="originalString">The original string.</param>
- //<returns>The encrypted string.</returns>
- //<exception cref="ArgumentNullExepction".This exception will be thrown.
- public static string encrypt(string orignialString)
- {
- if (String.IsNullOrempty(orignialString))
- {
- throw new ArgumentNullException("The string which needs to be encrypted can not be null;
- }
- DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
- MemoryStream memoryStream = new MemoryStream();
- CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateEncryptor);
- StreamWriter writer = new StreamWriter(cryptoStream);
- writer.Write(originalString);
- cryptoStream.FlushFinalBlock();
- writer.Flush();
- return Convert.ToBase64String(memoryStream.GetBuffer(), 0, (int)MemoryStream.Length);
- }
- public static string Decrypt(string cryptedString))
- {
- if (String.IsNullOrempty(cryptedString))
- {
- throw new ArgumentNullException("The string which needs to be decrypted can not be null
- }
- DESCryptoServiceProvider cryptoProvider = DESCryptoServiceProvider();
- MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(cryptedString));
- CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateDecryptor(_bytes, _bytes), CryptoStreamMode.Read);
- StreamReader reader = new StreamReader(cryptoStream);
- return reader.Read.ToEnd();
- }
- public static string HandleSQLSensitiveChars(string orignialText)
- {
- if (string.IsNullOrempty(originalText))
- {
- return String.Emtpy;
- }
- return original.replace("<". "<").Replace(">",">");
- }
- public static string ResumeSQLStoredText(string storedText)
- {
- if (String.IsNullOrempty(storableText))
- {
- return String.Empty;
- }
- #endregion
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement