SafeNet/.svn/pristine/2a/2a14e6ffcce30ebdcaa76f60b9cf55c760d0a9b5.svn-base
2021-02-24 13:50:23 +02:00

37 lines
1.3 KiB
Plaintext

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();
}
}
}