RijndaelManaged's question, how can I encrypt text more than 16bytes
- From: "Sam Shi" <samshi@xxxxxxxxx>
- Date: Fri, 16 Mar 2007 17:42:24 +0800
Hi, I'm using RijndaelManaged to encrypt data.
Encode method is
public static string DecodeText(string encryptext, string key, byte[]
machinekey)
{
byte[] bufencrypt = S_Misc.HexStringToByteArray(encryptext);
byte[] bufkey = S_Misc.HexStringToByteArray(key);
RijndaelManaged myRijndael = new RijndaelManaged();
ICryptoTransform decryptor = myRijndael.CreateDecryptor(bufkey,
machinekey);
MemoryStream msDecrypt = new MemoryStream(bufencrypt);
CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor,
CryptoStreamMode.Read);
StreamReader sr = new StreamReader(csDecrypt);
return sr.ReadToEnd();
}
public static string EncodeText(string text, string key, byte[]
machinekey)
{
byte[] bufpass = Encoding.ASCII.GetBytes(text);
byte[] bufkey = S_Misc.HexStringToByteArray(key);
byte[] buffer = null;
RijndaelManaged myRijndael = new RijndaelManaged();
ICryptoTransform encryptor = myRijndael.CreateEncryptor(bufkey,
machinekey);
MemoryStream msEncrypt = new MemoryStream();
CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor,
CryptoStreamMode.Write);
csEncrypt.Write(bufpass, 0, bufpass.Length);
csEncrypt.FlushFinalBlock();
buffer = msEncrypt.ToArray();
return S_Misc.ByteArrayToHexString(buffer);
}
test method:
string key = "12345678901234567890123456789012";
string mkey = "09876543210987654321098765432101";
string zkey = "00000000000000000000000000000000";
byte[] bmkey = S_Misc.HexStringToByteArray(mkey);
byte[] zmkey = S_Misc.HexStringToByteArray(zkey);
string entxt0 = EncodeText("12345678",key,bmkey);
string entxt1 = EncodeText("123456781234",key,bmkey);
string entxt2 = EncodeText("1234567812345678",key,bmkey);
string entxt3 = EncodeText("123456781234567812345678",key,bmkey);
string entxt4 = EncodeText("12345678123456781234567812345678",key,bmkey);
string entxt5 =
EncodeText("1234567812345678123456781234567812345678",key,bmkey);
string entxt6 =
EncodeText("123456781234567812345678123456781234567812345678",key,bmkey);
string detxt0 = DecodeText(entxt0,key,zmkey);
string detxt1 = DecodeText(entxt1,key,zmkey);
string detxt2 = DecodeText(entxt2,key,zmkey);
string detxt3 = DecodeText(entxt3,key,zmkey);
string detxt4 = DecodeText(entxt4,key,zmkey);
string detxt5 = DecodeText(entxt5,key,zmkey);
string detxt6 = DecodeText(entxt6,key,zmkey);
entxt0 "9A5653C0957DFE7364AB2BC6E4F8CD56" string
entxt1 "D6D0D00A3560A95C2A4F33B764E5B002" string
entxt2 "0E7EC566DE6BC1889A0D81DE518B402DF00DD1E16370C35B19719D8D870EB29F"
string
entxt3 "0E7EC566DE6BC1889A0D81DE518B402D4A85DD6DB6736C47B3F62AD3A425006D"
string
entxt4
"0E7EC566DE6BC1889A0D81DE518B402DC5E87043FBA92D9FB2C88861B451C4B456624F675057E5C8F5A5AA0CC554C878"
string
entxt5
"0E7EC566DE6BC1889A0D81DE518B402DC5E87043FBA92D9FB2C88861B451C4B405550148A876CB65DBE40C71DDDBCFB6"
string
entxt6
"0E7EC566DE6BC1889A0D81DE518B402DC5E87043FBA92D9FB2C88861B451C4B4D3D5E88E9F070699CFE6CED4951BCECAA2703B46DBE4D6A03B2D71C204580886"
string
detxt0 "8Vw?" string
detxt1 "8Vw?]r:" string
detxt2 "8Vw?]r:Pu9" string
detxt3 "8Vw?]r:Pu912345678" string
detxt4 "8Vw?]r:Pu91234567812345678" string
detxt5 "8Vw?]r:Pu9123456781234567812345678" string
detxt6 "8Vw?]r:Pu912345678123456781234567812345678" string
Note: I use deferent IV to EncodeText,DecodeText
The results show if a text's length is more than 16 bytes, only the first 16
bytes are well encrypted.
I want to know , how can I encrypt the rest text?
Thanks in advance for any reply!
Sam
.
- Prev by Date: Re: WindowsIdentity - Invalid token; it cannot be duplicated
- Next by Date: Re: RSACryptoServiceProvider minimum key-length
- Previous by thread: Removing the "Inherit permissions from parent" from an NTFS folder using System.Security.AccessControl
- Next by thread: Creating a PKCS#7 from a PKCS#1
- Index(es):
Relevant Pages
|