要加密的数据:我是谁啊
加密出来的数据:0Rfa/939iCv/SgFlPmwnTA==
老总说加密出来的数据是标准的asc码酱紫是不行的加密出来的数据里面应该有类似于
红桃 方块 梅花 星星 等 哪些火星文 啥弄嗫
代码如下using System;
using System.Security;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.IO;
public class TripleDES
{
public static string EncryptString(string encryptValue, string sKey)
{
string stringToEncrypt = (string)encryptValue; string SEncryptionKey = (string)sKey; byte[] IV = { 0xB0, 0xA2, 0xB8, 0xA3, 0xDA, 0xCC, 0xDA, 0xCC }; byte[] key = { }; try
{
key = System.Text.Encoding.UTF8.GetBytes(SEncryptionKey.Trim()); TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider(); des.Mode = CipherMode.ECB; des.Padding = System.Security.Cryptography.PaddingMode.PKCS7; byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write); cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (Exception ex)
{
return (string)ex.Message;
} } public static string DecryptString(string decryptValue, string sKey)
{
string stringToDecrypt = (string)decryptValue; string SDecryptionKey = (string)sKey; byte[] inputByteArray = new byte[stringToDecrypt.Length]; byte[] IV = { 0xB0, 0xA2, 0xB8, 0xA3, 0xDA, 0xCC, 0xDA, 0xCC }; byte[] key = { }; try
{
key = System.Text.Encoding.UTF8.GetBytes(SDecryptionKey.Trim()); TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider(); des.Mode = CipherMode.ECB; des.Padding = System.Security.Cryptography.PaddingMode.PKCS7; inputByteArray = Convert.FromBase64String(stringToDecrypt); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write); cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); System.Text.Encoding encoding = System.Text.Encoding.UTF8; return encoding.GetString(ms.ToArray());
}
catch (Exception ex)
{
return (string)ex.Message;
}
}
}
加密出来的数据:0Rfa/939iCv/SgFlPmwnTA==
老总说加密出来的数据是标准的asc码酱紫是不行的加密出来的数据里面应该有类似于
红桃 方块 梅花 星星 等 哪些火星文 啥弄嗫
代码如下using System;
using System.Security;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.IO;
public class TripleDES
{
public static string EncryptString(string encryptValue, string sKey)
{
string stringToEncrypt = (string)encryptValue; string SEncryptionKey = (string)sKey; byte[] IV = { 0xB0, 0xA2, 0xB8, 0xA3, 0xDA, 0xCC, 0xDA, 0xCC }; byte[] key = { }; try
{
key = System.Text.Encoding.UTF8.GetBytes(SEncryptionKey.Trim()); TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider(); des.Mode = CipherMode.ECB; des.Padding = System.Security.Cryptography.PaddingMode.PKCS7; byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write); cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (Exception ex)
{
return (string)ex.Message;
} } public static string DecryptString(string decryptValue, string sKey)
{
string stringToDecrypt = (string)decryptValue; string SDecryptionKey = (string)sKey; byte[] inputByteArray = new byte[stringToDecrypt.Length]; byte[] IV = { 0xB0, 0xA2, 0xB8, 0xA3, 0xDA, 0xCC, 0xDA, 0xCC }; byte[] key = { }; try
{
key = System.Text.Encoding.UTF8.GetBytes(SDecryptionKey.Trim()); TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider(); des.Mode = CipherMode.ECB; des.Padding = System.Security.Cryptography.PaddingMode.PKCS7; inputByteArray = Convert.FromBase64String(stringToDecrypt); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write); cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); System.Text.Encoding encoding = System.Text.Encoding.UTF8; return encoding.GetString(ms.ToArray());
}
catch (Exception ex)
{
return (string)ex.Message;
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货