RC2 is a variable key-size block cipher designed by Ronald Rivest for RSA Data Security (now RSA Security). "RC" stands for "Ron's Code" or "Rivest's Cipher.
Read more on CR2
/*
* csharp-home.com or nerdandy@gmail.com for questions and answers
* Enjoy!!
* */
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Security.Cryptography;
namespace Security
{
class GCript
{
byte[] gKey;
byte[] gIV;
byte[] gCypher;
string gData;
RC2CryptoServiceProvider gRC2;
public GCript()
{
gRC2 = new RC2CryptoServiceProvider();
gKey = gRC2.Key;
gIV = gRC2.IV;
}
public string GEnCript(string data)
{
gData=data;
ICryptoTransform gICTP = gRC2.CreateEncryptor(this.gKey, this.gIV);
MemoryStream gMS = new MemoryStream();
CryptoStream gCS = new CryptoStream(gMS, gICTP,CryptoStreamMode.Write);
byte[] gFormat = Encoding.ASCII.GetBytes(gData);
gCS.Write(gFormat, 0, gFormat.Length);
gCS.FlushFinalBlock();
gCypher = gMS.ToArray();
return Encoding.ASCII.GetString(gMS.ToArray());
}
public string GDeCript()
{
ICryptoTransform gDCTP = gRC2.CreateDecryptor(this.gKey, this.gIV);
MemoryStream? gMS = new MemoryStream(gCypher);
CryptoStream? gCS = new CryptoStream(gMS, gDCTP, CryptoStreamMode?.Read);
byte[] gDC = new bytegCypher.Length;
gCS.Read(gDC, 0, gCypher.Length);
return Encoding.ASCII.GetString(gDC);
}
}
}
0 comments:
Post a Comment