=?GB2312?B?suLK1NK7z8K/tL+0v8nE3MrVz8LAtA==?=
和
=?gb2312?Q?=B7=A2=D3=CA=BC=FE=C0=B2?=
怎么用语句出来编码与内容
我用的是下面这个,但中间的那个B是不确定的,而有可能是其它的字符如Q
=\\?(.+?)\\?B\\?(.+?)\\?=而且后面
=B7=A2=D3=CA=BC=FE=C0=B2?=
到底是怎么编码的?我用gb2312无法得到呀?我的代码如下:
System.Text.RegularExpressions.MatchCollection mc;
string strOriginalSubject;
string strSubject1 = string.Empty;
string strSubject = string.Empty;
string strChatset = string.Empty;
int iChatsetStartIndex;
int iSubjectStartIndex;
//@"=?GB2312?B?suLK1NK7z8K/tL+0v8nE3MrVz8LAtA==?="
//=?gb2312?Q?=B7=A2=D3=CA=BC=FE=C0=B2?=
strOriginalSubject = @"=?GB2312?B?suLK1NK7z8K/tL+0v8nE3MrVz8LAtA==?=";
mc = System.Text.RegularExpressions.Regex.Matches(strOriginalSubject, "=\\?(.+?)\\?B\\?(.+?)\\?=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);//"=\\?(.+?)\\?B\\?(.+?)\\?="
foreach (System.Text.RegularExpressions.Match m in mc)
{
strChatset = m.Groups[1].Value; //编码
strSubject1 = m.Groups[2].Value; //标题
if (strChatset != string.Empty)
{
//对主题进行解码
byte[] bSubject = System.Convert.FromBase64String(strSubject1);
strSubject = System.Text.Encoding.GetEncoding(strChatset).GetString(bSubject);
//需要连同编码规则一起替换掉
iChatsetStartIndex = strOriginalSubject.IndexOf("=?" + strChatset + "?");
if (iChatsetStartIndex < 0)
continue;
iSubjectStartIndex = strOriginalSubject.IndexOf("?" + strSubject1 + "?=", iChatsetStartIndex);
if (iSubjectStartIndex < 0)
continue;
strSubject1 = strOriginalSubject.Substring(iChatsetStartIndex, strChatset.Length + strSubject1.Length + 7);
strOriginalSubject = strOriginalSubject.Replace(strSubject1, strSubject);
}
}
MessageBox.Show(strOriginalSubject);
和
=?gb2312?Q?=B7=A2=D3=CA=BC=FE=C0=B2?=
怎么用语句出来编码与内容
我用的是下面这个,但中间的那个B是不确定的,而有可能是其它的字符如Q
=\\?(.+?)\\?B\\?(.+?)\\?=而且后面
=B7=A2=D3=CA=BC=FE=C0=B2?=
到底是怎么编码的?我用gb2312无法得到呀?我的代码如下:
System.Text.RegularExpressions.MatchCollection mc;
string strOriginalSubject;
string strSubject1 = string.Empty;
string strSubject = string.Empty;
string strChatset = string.Empty;
int iChatsetStartIndex;
int iSubjectStartIndex;
//@"=?GB2312?B?suLK1NK7z8K/tL+0v8nE3MrVz8LAtA==?="
//=?gb2312?Q?=B7=A2=D3=CA=BC=FE=C0=B2?=
strOriginalSubject = @"=?GB2312?B?suLK1NK7z8K/tL+0v8nE3MrVz8LAtA==?=";
mc = System.Text.RegularExpressions.Regex.Matches(strOriginalSubject, "=\\?(.+?)\\?B\\?(.+?)\\?=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);//"=\\?(.+?)\\?B\\?(.+?)\\?="
foreach (System.Text.RegularExpressions.Match m in mc)
{
strChatset = m.Groups[1].Value; //编码
strSubject1 = m.Groups[2].Value; //标题
if (strChatset != string.Empty)
{
//对主题进行解码
byte[] bSubject = System.Convert.FromBase64String(strSubject1);
strSubject = System.Text.Encoding.GetEncoding(strChatset).GetString(bSubject);
//需要连同编码规则一起替换掉
iChatsetStartIndex = strOriginalSubject.IndexOf("=?" + strChatset + "?");
if (iChatsetStartIndex < 0)
continue;
iSubjectStartIndex = strOriginalSubject.IndexOf("?" + strSubject1 + "?=", iChatsetStartIndex);
if (iSubjectStartIndex < 0)
continue;
strSubject1 = strOriginalSubject.Substring(iChatsetStartIndex, strChatset.Length + strSubject1.Length + 7);
strOriginalSubject = strOriginalSubject.Replace(strSubject1, strSubject);
}
}
MessageBox.Show(strOriginalSubject);
string yourStr = ..........;
Match m = Regex.Match(yourStr, @"=\?([^\?]*?)\?([^\?]*?)\?(.*?)\?=");
if (m.Success)
{
richTextBox2.Text += m.Groups[1].Value + "\n";
richTextBox2.Text += m.Groups[2].Value + "\n";
richTextBox2.Text += m.Groups[3].Value + "\n";
}输出分别为
string yourStr = "=?GB2312?B?suLK1NK7z8K/tL+0v8nE3MrVz8LAtA==?=";GB2312
B
suLK1NK7z8K/tL+0v8nE3MrVz8LAtA==string yourStr = "=?gb2312?Q?=B7=A2=D3=CA=BC=FE=C0=B2?=";gb2312
Q
=B7=A2=D3=CA=BC=FE=C0=B2
string pat = @"\?(\w+)\?(\w)\?([\w/+=?]+)";
Match m = Regex.Match(str, pat, RegexOptions.IgnoreCase); strChatset.Text = m.Groups[1].Value;
bq.Text = m.Groups[2].Value;
strSubject1.Text = m.Groups[3].Value;
非常感谢两位的回答,现在的问题是上面的这个到底是怎么加密的,我解密解不出来?
会在
byte[] bSubject = System.Convert.FromBase64String(strSubject1);
报错。也就是说他不是base64的?那这应该是什么的呢?
{
byte[] bytIn = System.Text.ASCIIEncoding.ASCII.GetBytes(Source);
// create a MemoryStream so that the process can be done without I/O files
System.IO.MemoryStream ms = new System.IO.MemoryStream();
byte[] bytKey = GetLegalKey(Key);
// set the private key
mobjCryptoService.Key = bytKey;
mobjCryptoService.IV = bytKey;
// create an Encryptor from the Provider Service instance
ICryptoTransform encrypto = mobjCryptoService.CreateEncryptor();
// create Crypto Stream that transforms a stream using the encryption
CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write);
// write out encrypted content into MemoryStream
cs.Write(bytIn, 0, bytIn.Length);
cs.FlushFinalBlock();
// get the output and trim the '\0' bytes
byte[] bytOut = ms.GetBuffer();
int i = 0;
for (i = 0; i < bytOut.Length; i++)
if (bytOut[i] == 0)
break;
// convert into Base64 so that the result can be used in xml
return System.Convert.ToBase64String(bytOut, 0, i);
}
public string Decrypting(string Source, string Key)
{
// convert from Base64 to binary
byte[] bytIn = System.Convert.FromBase64String(Source);
// create a MemoryStream with the input
System.IO.MemoryStream ms = new System.IO.MemoryStream(bytIn, 0, bytIn.Length);
byte[] bytKey = GetLegalKey(Key);
// set the private key
mobjCryptoService.Key = bytKey;
mobjCryptoService.IV = bytKey;
// create a Decryptor from the Provider Service instance
ICryptoTransform encrypto = mobjCryptoService.CreateDecryptor();
// create Crypto Stream that transforms a stream using the decryption
CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Read);
// read out the result from the Crypto Stream
System.IO.StreamReader sr = new System.IO.StreamReader( cs );
return sr.ReadToEnd();
}
//应该就是16进制编码,把等号去掉就是了