/// <summary> /// 解密函数 /// </summary> /// <param name="Content">解密内容</param> /// <param name="privateKey">私钥(XML格式)</param> /// <param name="rsaDes">经RSA加密后的desKey与desIV的集合</param> /// <param name="desKey">经RSA解密后的desKey</param> /// <param name="desIV">经RSA解密后的desKey</param> /// <returns>byte[]</returns> public byte[] DecryptBytes(string Content, string privateKey, string rsaDes, out string desKey, out string desIV) { byte[] byteResult = null; if (FunctionHelper.CheckValiable(rsaDes)) { // 解密DES密钥和初始化向量 RSACrypto RC = new RSACrypto(); string des = RC.RSADecrypt(privateKey, rsaDes); string[] desArray = FunctionHelper.SplitArray(des, '§'); desKey = desArray[0]; desIV = desArray[1]; // DES解密内容 DESCrypto DC = new DESCrypto(); byteResult = DC.DecryptBytes(Content, desKey, desIV); } else { desKey = ""; desIV = ""; byteResult = Convert.FromBase64String(Content); } return byteResult; }
/// <summary> /// 加密 byte[] 并返回 byte[] /// </summary> /// <param name="Content">加密内容</param> /// <param name="publicKey">公钥(XML格式)</param> /// <param name="desKey">DES密钥</param> /// <param name="desIV">DES向量</param> /// <param name="rsaDes">经RSA加密后的desKey与desIV的集合</param> /// <returns>byte[]</returns> public byte[] EncryptBytes(byte[] Content, string publicKey, string desKey, string desIV, out string rsaDes) { byte[] byteResult = null; if (FunctionHelper.CheckValiable(publicKey)) { // DES加密内容 DESCrypto DC = new DESCrypto(); byteResult = DC.EncryptBytes(Content, desKey, desIV); // 加密DES密钥和初始化向量 RSACrypto RC = new RSACrypto(); string des = desKey + "§" + desIV; rsaDes = RC.RSAEncrypt(publicKey, des); } else { rsaDes = ""; byteResult = Content; } return byteResult; }
/// <summary> /// 解密函数 /// </summary> /// <param name="Content">解密内容</param> /// <param name="privateKey">私钥(XML格式)</param> /// <param name="rsaDes">经RSA加密后的desKey与desIV的集合</param> /// <param name="desKey">经RSA解密后的desKey</param> /// <param name="desIV">经RSA解密后的desKey</param> /// <returns>string</returns> public string DecryptString(string Content, string privateKey, string rsaDes, out string desKey, out string desIV) { string strResult = ""; if (FunctionHelper.CheckValiable(rsaDes)) { // 解密DES密钥和初始化向量 RSACrypto RC = new RSACrypto(); string des = RC.RSADecrypt(privateKey, rsaDes); string[] desArray = FunctionHelper.SplitArray(des, '§'); desKey = desArray[0]; desIV = desArray[1]; // DES解密内容 DESCrypto DC = new DESCrypto(); strResult = DC.DecryptString(Content, desKey, desIV); } else { desKey = ""; desIV = ""; strResult = Content; } return strResult; }
/// <summary> /// 加密 byte[] 并返回 string /// </summary> /// <param name="Content">加密内容</param> /// <param name="publicKey">公钥(XML格式)</param> /// <param name="desKey">DES密钥</param> /// <param name="desIV">DES向量</param> /// <param name="rsaDes">经RSA加密后的desKey与desIV的集合</param> /// <returns>string</returns> public string EncryptString(byte[] Content, string publicKey, string desKey, string desIV, out string rsaDes) { string strResult = ""; if (FunctionHelper.CheckValiable(publicKey)) { // DES加密内容 DESCrypto DC = new DESCrypto(); strResult = DC.EncryptString(Content, desKey, desIV); // 加密DES密钥和初始化向量 RSACrypto RC = new RSACrypto(); string des = desKey + "§" + desIV; rsaDes = RC.RSAEncrypt(publicKey, des); } else { rsaDes = ""; strResult = Encoding.UTF8.GetString(Content); } return strResult; }