Click here to Skip to main content
15,910,224 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello..!!

i write code given below to encrypt text but i get error

string Does not contain definition for left.

the name Encoding is does not exist in current context.

actually this code is converted from VB.net to C#.net

anybody help me what can i do

C#
private static string Encrypt(string strText, string strEncrKey)
    {
        byte[] byKey = { };
        byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef };

        try
        {
            byKey = System.Text.Encoding.UTF8.GetBytes(string.Left(strEncrKey.ToString(), 8));
            //byKey = System.Text.Encoding.UTF8.GetBytes(string.left(strEncrKey, 8));

            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();

            return Convert.ToBase64String(ms.ToArray());
        }
        catch (Exception ex)
        {
            return ex.Message;

        }
    }


Thanks in advance.
Posted
Updated 19-May-10 23:53pm
v2
Comments
Henry Minute 20-May-10 8:44am    
Hi narendrarathod, for your future reference I think that you have misunderstood the voting system. If you think an answer is good vote 5. Only vote 1 if the answer is very, very poor. :)

1 solution

1) Replace Left with SubString

e.g.

byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.subString(0, 8));

2) Add a using statement to the top of your class

using System.Text;
 
Share this answer
 
Comments
narendrarathod 20-May-10 6:19am    
Reason for my vote of 1
its working nice

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900