各位鼠标可以点击不能移动移动不匀速怎么办

  这年头找个正经能用的东西那是真难,网上一搜索一大堆,正经能用的没几个,得,最后还是得靠自己,正巧遇上需要AES加解密的地方了,而且还是Java和C#间的相互加解密操作,这里做个备忘
  这里采用的加解密使用base64转码方法,ECB模式,PKCS5Padding填充,密码必须是16位,否则会报错哈
  模式:Java的ECB对应C#的System.Security.Cryptography.CipherMode.ECB
  填充方法:Java的PKCS5Padding对应C#System.Security.Cryptography.PaddingMode.PKCS7
  Java和C#版的加解密是互通的,也就是能相互加解密,编码明确指定了采用UTF-8,有需要其他编码方法的请自行扩展
package nb.tmall.
import java.security.NoSuchAlgorithmE
import java.security.SecureR
import javax.crypto.*;
import javax.crypto.spec.SecretKeyS
import sun.misc.*;
@SuppressWarnings("restriction")
public class EncryptUtil {
public static String aesEncrypt(String str, String key) throws Exception {
if (str == null || key == null) return null;
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key.getBytes("utf-8"), "AES"));
byte[] bytes = cipher.doFinal(str.getBytes("utf-8"));
return new BASE64Encoder().encode(bytes);
public static String aesDecrypt(String str, String key) throws Exception {
if (str == null || key == null) return null;
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key.getBytes("utf-8"), "AES"));
byte[] bytes = new BASE64Decoder().decodeBuffer(str);
bytes = cipher.doFinal(bytes);
return new String(bytes, "utf-8");
using System.Security.C
using System.T
namespace CSharp.Util.Security
/// &summary&
/// &/summary&
/// &param name="str"&&/param&
/// &param name="key"&&/param&
/// &returns&&/returns&
public static string AesEncrypt(string str, string key)
if (string.IsNullOrEmpty(str)) return null;
Byte[] toEncryptArray = Encoding.UTF8.GetBytes(str);
System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
Key = Encoding.UTF8.GetBytes(key),
Mode = System.Security.Cryptography.CipherMode.ECB,
Padding = System.Security.Cryptography.PaddingMode.PKCS7
System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateEncryptor();
Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
/// &summary&
/// &/summary&
/// &param name="str"&&/param&
/// &param name="key"&&/param&
/// &returns&&/returns&
public static string AesDecrypt(string str, string key)
if (string.IsNullOrEmpty(str)) return null;
Byte[] toEncryptArray = Convert.FromBase64String(str);
System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged
Key = Encoding.UTF8.GetBytes(key),
Mode = System.Security.Cryptography.CipherMode.ECB,
Padding = System.Security.Cryptography.PaddingMode.PKCS7
System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateDecryptor();
Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return Encoding.UTF8.GetString(resultArray);
阅读(...) 评论()利用C#实现AES加密算法加密文本信息--《信息安全与技术》2012年07期
利用C#实现AES加密算法加密文本信息
【摘要】:介绍了AES加密算法的基本原理,包括核心算法、密码分组及BASE64编码,在C#中调用.NET Framework的类库,实现了一个可变密钥分组长度的文本加密程序。
【作者单位】:
【关键词】:
【分类号】:TP309.7【正文快照】:
0引言1997年美国国家技术标准研究所(NIST)发起征集AES(Advanced Encryption Standard)算法的活动,目的是确定一个非保密的、公开算法的、全球免费使用的分组密码算法,用来替代原先的DES算法,用于保护21世纪政府的敏感信息。1998年从参选的15个候选算法中最终筛选出Rijndael
欢迎:、、)
支持CAJ、PDF文件格式,仅支持PDF格式
【相似文献】
中国期刊全文数据库
甘其先;宋秀丽;;[J];信息安全与通信保密;2011年09期
曹晓丽;王爱强;;[J];洛阳师范学院学报;2011年08期
;[J];;年期
;[J];;年期
;[J];;年期
;[J];;年期
;[J];;年期
;[J];;年期
;[J];;年期
;[J];;年期
中国重要会议论文全文数据库
李兴德;姚军刚;;[A];第六届全国计算机应用联合学术会议论文集[C];2002年
王铁肩;;[A];第二次计算机安全技术交流会论文集[C];1987年
陈伟;周继军;杨义先;;[A];全国网络与信息安全技术研讨会'2005论文集(下册)[C];2005年
中国博士学位论文全文数据库
姜晶菲;[D];国防科学技术大学;2004年
邓绍江;[D];重庆大学;2005年
王薇;[D];山东大学;2009年
杨欣;[D];重庆大学;2008年
王永;[D];重庆大学;2007年
向涛;[D];重庆大学;2008年
丁文霞;[D];国防科学技术大学;2008年
何希平;[D];重庆大学;2006年
曹明;[D];北京邮电大学;2008年
平萍;[D];南京理工大学;2009年
中国硕士学位论文全文数据库
吕士表;[D];厦门大学;2007年
叶朝岭;[D];哈尔滨理工大学;2009年
黄怡然;[D];华北电力大学(河北);2006年
黄玉蕾;[D];西安科技大学;2008年
杜宝萍;[D];山东师范大学;2012年
王哲;[D];山东师范大学;2012年
何晓静;[D];天津大学;2005年
贺达;[D];西南交通大学;2005年
于学荣;[D];解放军信息工程大学;2007年
张小平;[D];太原理工大学;2008年
&快捷付款方式
&订购知网充值卡
400-819-9993
《中国学术期刊(光盘版)》电子杂志社有限公司
同方知网数字出版技术股份有限公司
地址:北京清华大学 84-48信箱 大众知识服务
出版物经营许可证 新出发京批字第直0595号
订购热线:400-819-82499
服务热线:010--
在线咨询:
传真:010-
京公网安备75号c#AES加密,实现与Android&AES机密同步
using System.Collections.G
using System.IO;
using System.L
using System.Security.C
using System.T
namespace Test
AESEncryption
//默认密钥向量
private static byte[] _key1 = { 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 97, 98, 99, 100, 101, 102 };
/// AES加密算法
/// 明文字符串
/// 返回加密后的密文字节数组
public static byte[] AESEncrypt(string plainText, string
&&&&&&&&&&&
//分组加密算法
&&&&&&&&&&&
SymmetricAlgorithm des = Rijndael.Create();
&&&&&&&&&&&
byte[] inputByteArray =
Encoding.Default.GetBytes(plainText);//得到需要加密的字节数组
&&&&&&&&&&&
//设置密钥及密钥向量
&&&&&&&&&&&
des.Key = Encoding.Default.GetBytes(strKey);
&&&&&&&&&&&
des.IV = _key1;
&&&&&&&&&&&
MemoryStream ms = new MemoryStream();
&&&&&&&&&&&
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(),
CryptoStreamMode.Write);
&&&&&&&&&&&
cs.Write(inputByteArray, 0, inputByteArray.Length);
&&&&&&&&&&&
cs.FlushFinalBlock();
&&&&&&&&&&&
byte[] cipherBytes = ms.ToArray();//得到加密后的字节数组
&&&&&&&&&&&
cs.Close();
&&&&&&&&&&&
ms.Close();
&&&&&&&&&&&
return cipherB
/// AES解密
/// 密文字节数组
/// 返回解密后的字符串
public static byte[] AESDecrypt(byte[] cipherText, string
&&&&&&&&&&&
SymmetricAlgorithm des = Rijndael.Create();
&&&&&&&&&&&
des.Key = Encoding.Default.GetBytes(strKey);
&&&&&&&&&&&
des.IV = _key1;
&&&&&&&&&&&
byte[] decryptBytes = new byte[cipherText.Length];
&&&&&&&&&&&
MemoryStream ms = new MemoryStream(cipherText);
&&&&&&&&&&&
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(),
CryptoStreamMode.Read);
&&&&&&&&&&&
cs.Read(decryptBytes, 0, decryptBytes.Length);
&&&&&&&&&&&
cs.Close();
&&&&&&&&&&&
ms.Close();
&&&&&&&&&&&
return decryptB
/// 字符串转16进制字节数组
public static byte[] strToToHexByte(string hexString)
&&&&&&&&&&&&
hexString = hexString.Replace(" ", "");
&&&&&&&&&&
if ((hexString.Length % 2) != 0)
&&&&&&&&&&&&&&&&
hexString += " ";
&&&&&&&&&&&
byte[] returnBytes = new byte[hexString.Length / 2];
&&&&&&&&&&&
for (int i = 0; i & returnBytes.L i++)
&&&&&&&&&&&&&&&
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2),
&&&&&&&&&&&
return returnB
/// 字节数组转16进制字符串
public static string byteToHexStr(byte[] bytes)
&&&&&&&&&&&
string returnStr = "";
&&&&&&&&&&&
if (bytes != null)
&&&&&&&&&&&
&&&&&&&&&&&&&&&
for (int i = 0; i & bytes.L i++)
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&
returnStr += bytes[i].ToString("X2");
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&
return returnS
/// 从汉字转换到16进制
/// 编码,如"utf-8","gb2312"
/// 是否每字符用逗号分隔
public static string ToHex(string s, string charset, bool
&&&&&&&&&&&
if ((s.Length % 2) != 0)
&&&&&&&&&&&
&&&&&&&&&&&&&&&&
s += " ";//空格
&&&&&&&&&&&&&&&
//throw new ArgumentException("s is not valid chinese
string!");
&&&&&&&&&&&&
&&&&&&&&&&&&
System.Text.Encoding chs =
System.Text.Encoding.GetEncoding(charset);
&&&&&&&&&&&
byte[] bytes = chs.GetBytes(s);
&&&&&&&&&&&
string str = "";
&&&&&&&&&&&
for (int i = 0; i & bytes.L i++)
&&&&&&&&&&&
&&&&&&&&&&&&&&&
str += string.Format("{0:X}", bytes[i]);
&&&&&&&&&&&&&&&
if (fenge && (i != bytes.Length - 1))
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&
str += string.Format("{0}", ",");
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&
return str.ToLower();
/// 从16进制转换成汉字
/// 编码,如"utf-8","gb2312"
public static string UnHex(string hex, string charset)
&&&&&&&&&&
if (hex == null)
&&&&&&&&&&&&&&&
throw new ArgumentNullException("hex");
&&&&&&&&&&&&
hex = hex.Replace(",", "");
&&&&&&&&&&&&
hex = hex.Replace("\n", "");
&&&&&&&&&&&&
hex = hex.Replace("\\", "");
&&&&&&&&&&&&
hex = hex.Replace(" ", "");
&&&&&&&&&&&
if (hex.Length % 2 != 0)
&&&&&&&&&&&
&&&&&&&&&&&&&&&&
hex += "20";//空格
&&&&&&&&&&&&
&&&&&&&&&&&
// 需要将 hex 转换成 byte 数组。
&&&&&&&&&&&
byte[] bytes = new byte[hex.Length / 2];
&&&&&&&&&&
for (int i = 0; i & bytes.L i++)
&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
// 每两个字符是一个 byte。
&&&&&&&&&&&&&&&&&&&&
bytes[i] = byte.Parse(hex.Substring(i * 2, 2),
&&&&&&&&&&&&&&&&&&&&
System.Globalization.NumberStyles.HexNumber);
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&
// Rethrow an exception with custom message.
&&&&&&&&&&&&&&&&&&&
throw new ArgumentException("hex is not a valid hex number!",
&&&&&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&
System.Text.Encoding chs =
System.Text.Encoding.GetEncoding(charset);
&&&&&&&&&&&
return chs.GetString(bytes);
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。}

我要回帖

更多关于 lol鼠标不能移动屏幕 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信