我有一些问题,我不能定义原因。
我有解密一些信息的函数,返回值是一个从二进制转换为字符串的字符串。
public static string Decrypt(string encryptedText, string completeEncodedKey, int keySize)
{
RijndaelManaged aesEncryption = new RijndaelManaged();
aesEncryption.KeySize = keySize;
aesEncryption.BlockSize = 128;
aesEncryption.Mode = CipherMode.CBC;
aesEncryption.Padding = PaddingMode.Zeros;
aesEncryption.IV = Convert.FromBase64String(ASCIIEncoding.UTF8.GetString(Convert.FromBase64String(completeEncodedKey)).Split(',')[0]);
aesEncryption.Key = Convert.FromBase64String(ASCIIEncoding.UTF8.GetString(Convert.FromBase64String(completeEncodedKey)).Split(',')[1]);
ICryptoTransform decrypto = aesEncryption.CreateDecryptor();
byte[] encryptedBytes = Convert.FromBase64CharArray(encryptedText.ToCharArray(), 0, encryptedText.Length);// convert the cipertext to binary
string RESULT = (string)ASCIIEncoding.UTF8.GetString(decrypto.TransformFinalBlock(encryptedBytes, 0, encryptedBytes.Length));//convert the binary to string
return RESULT;
}当我调用此函数并获取结果,然后尝试使用其他字符串显示结果时,出现了问题,例如通过以下消息框:
String result= function.Decrypt(textToBeDecrypted, key, 128);
MessageBox.Show("This is sample text " + result + " here i want to append another string ");只显示附加的文本(在本例中:“here I want to append another string ")
这有什么问题吗?
发布于 2013-04-30 03:43:56
试试这个:
string result = function.Decrypt(textToBeDecrypted, key, 128).Replace("\0", string.Empty);发布于 2013-04-30 03:30:57
http://bytes.com/topic/c-sharp/answers/275256-rijndael-decrypt-returning-escape-characters-end-string
看起来是一样的问题。我打赌你的末尾有一个转义字符(\0)。
发布于 2013-04-30 03:48:03
aesEncryption.Padding = PaddingMode.Zeros;您在邮件末尾添加了零...就Win32 MessageBox应用编程接口而言,字符串的结尾为零。
在解密过程中删除填充(使用不同的填充模式会更容易)。
https://stackoverflow.com/questions/16286590
复制相似问题