37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Security.Cryptography;
|
|
using System.IO;
|
|
|
|
namespace ConsoleApplication1
|
|
{
|
|
static public class Encryption
|
|
{
|
|
static byte[] bytes = ASCIIEncoding.ASCII.GetBytes("SafeMobi"); //DES 64bit !
|
|
|
|
static public byte[] Encrypt(byte[] inputArray)
|
|
{
|
|
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateEncryptor(bytes, bytes), CryptoStreamMode.Write);
|
|
|
|
cryptoStream.Write(inputArray, 0, inputArray.Length);
|
|
|
|
cryptoStream.Close(); memoryStream.Close();
|
|
return memoryStream.ToArray();
|
|
}
|
|
|
|
static public byte[] Decrypt(byte[] DataToDecrypt)
|
|
{
|
|
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
|
|
MemoryStream memoryStream = new MemoryStream();
|
|
CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoProvider.CreateDecryptor(bytes, bytes), CryptoStreamMode.Write);
|
|
|
|
cryptoStream.Write(DataToDecrypt, 0, DataToDecrypt.Length);
|
|
cryptoStream.Close(); memoryStream.Close();
|
|
return memoryStream.ToArray();
|
|
}
|
|
}
|
|
}
|