0

hi I have a problem or using Decrypt SelectInfo

Error invalid length for a base-64 char array

Where does my code have problems?

public static string InsertAndUpdate(string strValue, string Value) {

        byte[] byKey;
        byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
        try
        {
            byKey = System.Text.Encoding.UTF8.GetBytes(Value.Substring(0, 8));
            System.Security.Cryptography.DESCryptoServiceProvider des = new System.Security.Cryptography.DESCryptoServiceProvider();
            byte[] inputByteArray = System.Text.Encoding.UTF8.GetBytes(strValue);
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(byKey, IV), System.Security.Cryptography.CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();
            return Convert.ToBase64String(ms.ToArray());
        }
        catch (Exception E)
        {
            throw E;
        }

    }

    public static string SelectInfo(string strValue, string Value)
    {
        byte[] byKey;
        byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
        byte[] inputByteArray;
        //inputByteArray.Length = strText.Length;
        try
        {
            byKey = System.Text.Encoding.UTF8.GetBytes(Value.Substring(0, 8));
            System.Security.Cryptography.DESCryptoServiceProvider des = new System.Security.Cryptography.DESCryptoServiceProvider();
            inputByteArray = Convert.FromBase64String(strValue);
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(byKey, IV), System.Security.Cryptography.CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();
            System.Text.Encoding encoding = System.Text.Encoding.UTF8;
            return encoding.GetString(ms.ToArray());
        }
        catch (Exception E)
        {

            throw E;
        }
TheGeneral
  • 79,002
  • 9
  • 103
  • 141

0 Answers0