8276
General Software Discussion / Re: functional C# class/component to upload to my DC space via explicit FTP over TLS
« Last post by wraith808 on May 14, 2011, 09:40 AM »You could also use encryption, and get it from a file if you want to use FTP.
Code: C# [Select]
- using System;
- using System.Security.Cryptography;
- using System.Text;
- namespace Coderz808
- {
- public static class EnDeCrypter
- {
- // Set this to some personalized crypto key
- private const string cryptoKey = "someSortOfCryptoKey";
- // The Initialization Vector for the DES encryption routine (choose 8 personalized bytes)
- private static readonly byte[] IV =
- /// <summary>
- /// Encrypts provided string parameter
- /// </summary>
- internal static string Encrypt(string s)
- {
- if (s == null || s.Length == 0) return string.Empty;
- string result = string.Empty;
- try
- {
- byte[] buffer = Encoding.ASCII.GetBytes(s);
- TripleDESCryptoServiceProvider des =
- MD5CryptoServiceProvider MD5 =
- des.Key =
- MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(cryptoKey));
- des.IV = IV;
- result = Convert.ToBase64String(
- des.CreateEncryptor().TransformFinalBlock(
- buffer, 0, buffer.Length));
- }
- catch
- {
- throw;
- }
- return result;
- }
- /// <summary>
- /// Decrypts provided string parameter
- /// </summary>
- internal static string Decrypt(string s)
- {
- if (s == null || s.Length == 0) return string.Empty;
- string result = string.Empty;
- try
- {
- byte[] buffer = Convert.FromBase64String(s);
- TripleDESCryptoServiceProvider des =
- MD5CryptoServiceProvider MD5 =
- des.Key =
- MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(cryptoKey));
- des.IV = IV;
- result = Encoding.ASCII.GetString(
- des.CreateDecryptor().TransformFinalBlock(
- buffer, 0, buffer.Length));
- }
- catch
- {
- throw;
- }
- return result;
- }
- }
- }

Recent Posts



