TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Paul Rajs
NA
641
146.9k
Length of the data to decrypt is invalid - Solve
May 15 2021 10:31 AM
Hi Developers,
I have created a new windows form application for Decrypt a string with password. Its working fine.
But sometime if the length is too it throws the following error.
"Length of the data to decrypt is invalid"
AES password : 8468A97B4373415365537265744B6579746869834973215365637261745B6579
public static byte[] AES_DECRYPT(string text, string hexPassword)
{
byte[] originalBytes = HexStringToByte(text);
byte[] passwordBytes = HexStringToByte(hexPassword);
byte[] encryptedBytes = null;
using (MemoryStream ms = new MemoryStream())
{
using (RijndaelManaged AES = new RijndaelManaged())
{
AES.Padding = PaddingMode.Zeros;
AES.Key = passwordBytes;
AES.Mode = CipherMode.ECB;
using (CryptoStream cs = new CryptoStream(ms, AES.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(originalBytes, 0, originalBytes.Length);
cs.Close();
}
encryptedBytes = ms.ToArray();
}
}
return encryptedBytes;
}
for text
private static byte[] HexStringToByte(string hexString)
{
try
{
int bytesCount = (hexString.Length) / 2;
byte[] bytes = new byte[bytesCount];
for (int x = 0; x < bytesCount; ++x)
{
bytes[x] = Convert.ToByte(hexString.Substring(x * 2, 2), 16);
}
return bytes;
}
catch
{
throw;
}
}
for password
private static byte[] HexStringToByte(string hexString)
{
try
{
int bytesCount = (hexString.Length) / 2;
byte[] bytes = new byte[bytesCount];
for (int x = 0; x < bytesCount; ++x)
{
bytes[x] = Convert.ToByte(hexString.Substring(x * 2, 2), 16);
}
return bytes;
}
catch
{
throw;
}
}
plese suggest me how to fix this error. Am using the following code
Thanks & Regards
Paul.S
Reply
Answers (
1
)
Automatically Display EmployeeName When enter Employeecode in mvc
Uploading Image with API and javascript