20分求助:AES加密,去除特殊符号,只有字母和数字

therealsun 2015-03-14 02:29:29
本人想用AES加密,加密后只有字母和数字,怎么样才能实习啊?
以下是我目前用的:

private static byte[] Keys = { 0x00, 0xxx, 0xa, 08x, 0x0, 0x12, 0x24, 0xc, 0xa, 0x8, 0x8, 0x23, 0xb, 0xa, 0x1, 0x12 };
/// <summary>AES加密字符串</summary>
/// <param name="encryptString">待加密的字符串</param>
/// <param name="encryptKey">加密密钥,要求为8位</param>
/// <returns>加密成功返回加密后的字符串,失败返回源串</returns>
public static string Encode(string encryptString, string encryptKey)
{
encryptKey = XString.GetSubString(encryptKey, 32, "");
encryptKey = encryptKey.PadRight(32, ' ');
RijndaelManaged rijndaelProvider = new RijndaelManaged();
rijndaelProvider.Key = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 32));
rijndaelProvider.IV = Keys;
ICryptoTransform rijndaelEncrypt = rijndaelProvider.CreateEncryptor();
byte[] inputData = Encoding.UTF8.GetBytes(encryptString);
byte[] encryptedData = rijndaelEncrypt.TransformFinalBlock(inputData,0,inputData.Length);
return Convert.ToBase64String(encryptedData);
}
...全文
8358 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
於黾 2015-08-11
  • 打赏
  • 举报
回复
要么别用AES加密 要么把AES加密的结果再转数字
by_封爱 版主 2015-08-11
  • 打赏
  • 举报
回复
首先 你为啥要这样做呢? 如果有特殊符号或者斜杠对你的程序有什么影响吗? 如果非得要数字+字母 你这样好了 把你得到的字符串转换成byte[] 然后对应16进制的字符串加一起 肯定是数组+字母了.
Poopaye 2015-08-11
  • 打赏
  • 举报
回复 1
引用 1 楼 therealsun 的回复:
以上加密后有斜杠、百分号、等号。。。。 不要特殊符号,只要字母和数字结合
把return那一句话替换成
return BitConverter.ToString(encryptedData).Replace("-", "");
kuailebaobaowoaini 2015-08-11
  • 打赏
  • 举报
回复
$encrypted=str_replace('+','-',$encrypted); $encrypted=str_replace('/','_',$encrypted); $encrypted=str_replace('=','*',$encrypted); next decrypt $encipheredData=str_replace('-','+',$encipheredData); $encipheredData=str_replace('_','/',$encipheredData); $encipheredData=str_replace('*','=',$encipheredData); it will works
  • 打赏
  • 举报
回复
任何加密在内存中它就是一段byte[],这个你可以直接Convert.ToBase64(),出来的也就字符数字字符外加等号
本拉灯 2015-03-14
  • 打赏
  • 举报
回复 1
那你就不能转成Base64 你转成BytToString 用下面的方法


public static byte[] HexToBytes(string Hex)
		{
			int num = (int) Math.Round((double) (((double) Hex.Length) / 2));
			byte[] buffer = new byte[(num - 1) + 1];
			int num3 = num - 1;
			for (int i = 0; i <= num3; i++)
			{
				string s = Hex.Substring(i * 2, 2);
				buffer[i] = (byte) int.Parse(s, NumberStyles.HexNumber);
			}
			return buffer;
		}
			
		public static string BytesToHex(byte[] bytes)
		{
			StringBuilder builder = new StringBuilder();
			int num2 = bytes.Length - 1;
			for (int i = 0; i <= num2; i++)
			{
				builder.AppendFormat("{0:X2}", bytes[i]);
			}
			return builder.ToString();
		}


therealsun 2015-03-14
  • 打赏
  • 举报
回复
或者如何不出现斜杠也行啊
therealsun 2015-03-14
  • 打赏
  • 举报
回复
以上加密后有斜杠、百分号、等号。。。。 不要特殊符号,只要字母和数字结合

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧