none
Moderators..please help...3DES decryption FlushFinalBlock error RRS feed

  • Question

  • Hey, I am using 3DES for encryption and decryption in my application. Encryption is working fine, I am facing problems while decrypting the field. The problem is when the debug control comes to finalflushblock and says bad data.
    M pasting some amount of code that I have used. Appreciate if some one can assist me urgently.

    public

    static string CmdEncrypt(string in_username,string in_pwd)

     

    string txtEncrypt = EncryptString(in_username,in_pwd);

     

    return txtEncrypt;

     

    // public SymmetricAlgorithm mCSP;

     

    public static string EncryptString(string strName, string strPwd)

     

    byte[] byt;

     

    new TripleDESCryptoServiceProvider();

     

    string txtKey = Convert.ToBase64String(mCSP.Key);

     

    string txtIV = Convert.ToBase64String(mCSP.IV);

     

    string strConnString = ConfigurationSettings.AppSettings["ConnString"];

     

    new OracleParameter("P_USER_NAME",OracleType.VarChar,15,ParameterDirection.Input,true,0,0,"",DataRowVersion.Default,strName.ToString().ToUpper().Trim()),

     

    new OracleParameter("P_H_KEY",OracleType.VarChar,50,ParameterDirection.Input,true,0,0,"",DataRowVersion.Default,txtKey.ToString().ToUpper().Trim()),

     

    new OracleParameter("P_IV",OracleType.VarChar,50,ParameterDirection.Input,true,0,0,"",DataRowVersion.Default,txtIV.ToString().ToUpper().Trim())

     

    new MemoryStream();

     

    new CryptoStream(ms, ct, CryptoStreamMode.Write);

     

    return Convert.ToBase64String(ms.ToArray());

     

    public static string CmdDecrypt(string in_enc_data,string txtKey, string txtIV)

     

    string txtDecrypt = DecryptString(in_enc_data,txtKey,txtIV);

     

    return txtDecrypt;

     

    public static string DecryptString(string strEncData, string strKey, string strIV)

     

    byte[] byt;

    // SymmetricAlgorithm mCSP=SymmetricAlgorithm.Create();

    SymmetricAlgorithm mCSP =

    new TripleDESCryptoServiceProvider();

     

    new MemoryStream();

     

    new CryptoStream(ms,ct,CryptoStreamMode.Write);

     

    return Encoding.UTF8.GetString(ms.ToArray());

     

     

    }

     

    cs.Write(byt,0,byt.Length);

    cs.FlushFinalBlock();

    cs.Close();

     

     

     

     

    mCSP.Key = Convert.FromBase64String(strKey);

    mCSP.IV = Convert.FromBase64String(strIV);

    ct = mCSP.CreateDecryptor(mCSP.Key,mCSP.IV);

    byt = Convert.FromBase64String(strEncData);

    ms =

     

    {

    ICryptoTransform ct;

    MemoryStream ms;

    CryptoStream cs;

     

     

    }

     

     

     

    {

     

     

    }

     

     

    cs.Write(byt, 0, byt.Length);

    cs.FlushFinalBlock();

    cs.Close();

     

     

     

    };

     

    OracleHelper.ExecuteNonQuery(strConnString, CommandType.StoredProcedure, "PKG_USER.Update_EN_Data",ps);

    ct = mCSP.CreateEncryptor(mCSP.Key, mCSP.IV);

    byt = Encoding.UTF8.GetBytes(strPwd);

    ms =

     

     

     

    OracleParameter[] ps = {

     

     

     

     

     

    mCSP.GenerateIV();

     

     

    mCSP.GenerateKey();

     

     

    SymmetricAlgorithm mCSP=SymmetricAlgorithm.Create();

     

    mCSP =

     

    {

    ICryptoTransform ct;

    MemoryStream ms;

    CryptoStream cs;

     

     

    }

     

     

     

    {

     

    cs =

     

    cs =

     

     

     

    • Edited by Nidz8272 Tuesday, May 26, 2009 5:46 AM
    Friday, May 22, 2009 11:54 AM

All replies