Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
输入数据不是一个完整的块。c#_C#_Database_Oracle_Encryption - Fatal编程技术网

输入数据不是一个完整的块。c#

输入数据不是一个完整的块。c#,c#,database,oracle,encryption,C#,Database,Oracle,Encryption,它在cs.Close()处向我抛出一个错误 错误在于输入数据不是完整的块 我实际上在做密码加密和解密。 加密没有问题,但当谈到解密,首先它说不能从基64转换,所以我补充说 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.IO; using System.Text; using System.Data; using System.Data.SqlCli

它在
cs.Close()处向我抛出一个错误
错误在于输入数据不是完整的块

我实际上在做密码加密和解密。 加密没有问题,但当谈到解密,首先它说不能从基64转换,所以我补充说

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Security.Cryptography;
namespace SOMaintenance.App_Code
{
    public class passwordsecurity
    {

        public string Encrypt(string clearText)
        {
            string EncryptionKey = "SWISSLOGMALAYSIA";
            byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);
            using (Aes encryptor = Aes.Create())
            {
                Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
                encryptor.Key = pdb.GetBytes(32);
                encryptor.IV = pdb.GetBytes(16);
                using (MemoryStream ms = new MemoryStream())
                {
                    using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(clearBytes, 0, clearBytes.Length);
                        cs.Close();
                    }
                    clearText = Convert.ToBase64String(ms.ToArray());
                }
            }
            return clearText;
        }

        internal string Decrypt(string cipherText)
        {
            int mod4 = cipherText.Length % 4;
            if (mod4 > 0)
            {
                cipherText += new string('=', 4 - mod4);
            }
            string EncryptionKey = "SWISSLOGMALAYSIA";
            byte[] cipherBytes = Convert.FromBase64String(cipherText);
            using (Aes encryptor = Aes.Create())
            {
                Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
                encryptor.Key = pdb.GetBytes(32);
                encryptor.IV = pdb.GetBytes(16);
                using (MemoryStream ms = new MemoryStream())
                {
                    using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(cipherBytes, 0, cipherBytes.Length);
                        cs.Close();
                    }
                    cipherText = Encoding.Unicode.GetString(ms.ToArray());
                }
            }
            return cipherText;
        }
    }
}
然后它把我现在面临的错误抛给了我。希望有人能在这方面帮助我。
感谢并感谢

oracle数据库是如何进入的?因为我是从oracle数据库检索的,我不确定数据库中的数据类型是否会影响它。。起初,我无法从base 64转换,我只是想为能够帮助我的人提供更多信息。。
int mod4 = cipherText.Length % 4;
if (mod4 > 0)
{
   cipherText += new string('=', 4 - mod4);
}