Introduction
This class contains methods/functions for easily decrypting and encrypting data.
This is a code file that you can include in your solution in Visual Studio, or a code to add to your current projects, or files elsewhere.
Description
This is code for encrypting and decrypting data, it is made to make it really easy to make applications that should contain encryption, and/or send encrypted data. This class is using: System; System. Security; System.Security.Cryptography.
How to initialize XiteEncryption?
Xite.Encryption myCrypto = new Xite.Encryption();
How to encrypt a message?
byte[] myEncryptedData = myCrypto.EncryptData(System.Text.ASCIIEncoding.ASCII.GetBytes("Your Message here!"));
How to decrypt the encrypted message?
string myDecryptedData = System.Text.ASCIIEncoding.ASCII.GetString(myCrypto.DecryptData(myEncryptedData));
Source Code
using System;
using System.Security;
using System.Security.Cryptography;
namespace Xite
{
public class Encryption
{
// Encryption made easy with RSA
// Both in and out data is in ByteArrays
// @Copyright(C)2002 Kjetil Red
//
// This file/code may freely be used in your solution
// Just add this file to your solution and access it like
// shown in the examples below.
//
// Example: How to initialize XiteEncryption?
// Xite.Encryption myCrypto = new Xite.Encryption();
//
// Example: How to encrypt a message?
// byte[] myEncryptedData = myCrypto.EncryptData(System.Text.ASCIIEncoding.ASCII.GetBytes("Your Message here!"));
//
// Example: How to decrypt the encrypted message?
// (Remember that the encrypted data is in a byteArray; it's returned as a byteArray when encrypted
// string myDecryptedData = System.Text.ASCIIEncoding.ASCII.GetString(myCrypto.DecryptData(myEncryptedData));
//
// Happy Crypting :)
// Initializing the RSA Cryptography Service Provider (CSP)
RSACryptoServiceProvider RSAXiteProvider = new RSACryptoServiceProvider();
// Declaring the Output data as a bytearray
private byte[] XiteOutputMsg = null;
public byte[] EncryptData(byte[] XiteData)
{
// Encrypting the data received
XiteOutputMsg = RSAXiteProvider.Encrypt(XiteData, true);
// Returning the data decrypted
return (XiteOutputMsg);
}
public byte[] DecryptData(byte[] XiteData)
{
// Decrypting the encrypted data received
XiteOutputMsg = RSAXiteProvider.Decrypt(XiteData, true);
// Returning the data decrypted and in its original form
return (XiteOutputMsg);
}
}
}