AES加密字符串的最大长度只能8位吗?
用AES加密字符串,再解密后,解密出的字符串只有最初字符串的前8位了,8位以后的字符都丢掉了,请问是怎么回事?比如我要加密"1234567890",再解密后,只剩下"12345678"了。是不是类本身的限制,还是我代码里面限制了?以下是我的代码。
public string AESEncrypt (AES.KeySize keySize, string Input)
{
byte[] input = new byte[16];
byte[] output = new byte[16];
AES aes = new AES (keySize, new byte[16]);
input = Encoding.Unicode.GetBytes (Input.PadRight (8, ' '));
aes.Cipher (input, output);
return Encoding.Unicode.GetString (output);
}
public string AESDecode(AES.KeySize keySize,string Input)
{
byte[] input = new byte[16];
byte[] output = new byte[16];
input = Encoding.Unicode.GetBytes(Input);
AES aes = new AES(keySize,new byte[16]);
aes.InvCipher(input,output);
return Encoding.Unicode.GetString(output);
}
//点击按钮加密
private void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text = AESEncrypt(Namespace.AES.KeySize.Bits256 ,TextBox1.Text);
}
//点击按钮解密
private void Button2_Click(object sender, System.EventArgs e)
{
Label2.Text = AESDecode(Namespace.AES.KeySize.Bits256, AESEncrypt(Namespace.AES.KeySize.Bits256 ,TextBox1.Text));
}
public string AESEncrypt (AES.KeySize keySize, string Input)
{
byte[] input = new byte[16];
byte[] output = new byte[16];
AES aes = new AES (keySize, new byte[16]);
input = Encoding.Unicode.GetBytes (Input.PadRight (8, ' '));
aes.Cipher (input, output);
return Encoding.Unicode.GetString (output);
}
public string AESDecode(AES.KeySize keySize,string Input)
{
byte[] input = new byte[16];
byte[] output = new byte[16];
input = Encoding.Unicode.GetBytes(Input);
AES aes = new AES(keySize,new byte[16]);
aes.InvCipher(input,output);
return Encoding.Unicode.GetString(output);
}
//点击按钮加密
private void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text = AESEncrypt(Namespace.AES.KeySize.Bits256 ,TextBox1.Text);
}
//点击按钮解密
private void Button2_Click(object sender, System.EventArgs e)
{
Label2.Text = AESDecode(Namespace.AES.KeySize.Bits256, AESEncrypt(Namespace.AES.KeySize.Bits256 ,TextBox1.Text));
}
...全文
相关推荐
AES加密任意长度的字符串和任意大小的文件
在描述中提到的问题,即“网上很多代码只能加密长度有限的字符串”,这通常是因为这些代码采用了固定大小的块进行操作,而AES加密算法是基于块的,标准的AES块大小为128位(16字节)。
AES128位加密过程详解
"AES128位加密过程详解"AES(Advanced Encryption Standard),即高级加密标准,是一种广泛应用的块加密算法。2000年,NIST(美国国家标准和技术协会)将其选
Java实现AES加密和解密算法
AES算法是一种块密码,采用固定大小的128位(16字节)块进行加密和解密,支持128、192和256位的密钥长度。在给定的代码示例中,AES算法被用于加密和解密字符串数据。
java AES加密 解决加密过长非法异常问题
**基于字符串的AES加密**: - 首先,需要将字符串转换为字节数组,可以使用UTF-8编码。
AES实现对字符串以及文件加密
AES有三种块大小(128位)、四种密钥长度(128、192、256位)和十轮或十二轮的加密过程,具体取决于密钥长度。2. **C语言实现**: C语言是一种底层编程语言,适合编写效率高的加密算法。


