以上就是给各位分享织梦dede5.7,dedecms5.7utf8首页分页,首页文档分页,其中也会对织梦的首页怎么换图片进行解释,同时本文还将给你拓展'str=newString(bytes,“UTF
以上就是给各位分享织梦 dede5.7,dedecms 5.7 utf8 首页分页,首页文档分页,其中也会对织梦的首页怎么换图片进行解释,同时本文还将给你拓展'str = new String(bytes,“ UTF8”)'和'bytes = str.getBytes(“ UTF8”)'中的字节数不相同、c# – Convert.ToBase64String / Convert.FromBase64String和Encoding.UTF8.GetBytes / Encoding.UTF8.GetString之间的区别、c# – Encoding.UTF8.GetString和Encoding.UTF8.GetBytes彼此不相反的原因是什么?、dede5.3生成列表假死问题的解决办法等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:- 织梦 dede5.7,dedecms 5.7 utf8 首页分页,首页文档分页(织梦的首页怎么换图片)
- 'str = new String(bytes,“ UTF8”)'和'bytes = str.getBytes(“ UTF8”)'中的字节数不相同
- c# – Convert.ToBase64String / Convert.FromBase64String和Encoding.UTF8.GetBytes / Encoding.UTF8.GetString之间的区别
- c# – Encoding.UTF8.GetString和Encoding.UTF8.GetBytes彼此不相反的原因是什么?
- dede5.3生成列表假死问题的解决办法
织梦 dede5.7,dedecms 5.7 utf8 首页分页,首页文档分页(织梦的首页怎么换图片)
功能:可以实现在首页使用 {dede:list} 以及 {dede:pagelist} 标签,并且生成的时候可以将首页分页 index.html index_1.html index_2.html……进后台模块管理新增模块,导入 xml 文件。
除了 xml 文件,其他的上传到根目录,有覆盖的覆盖,不影响原功能的使用 (若有对提示覆盖文件做过二次开发,请注意备份);
下载地址:
新浪爱问
CSDN
'str = new String(bytes,“ UTF8”)'和'bytes = str.getBytes(“ UTF8”)'中的字节数不相同
我可以看到它们与我创建字符串所用的字节不同!我已经使用“ AES / CBC / PKCS5Padding”来获取字符串。
public static void main(String[] args) { try { int randomNumber = CNStationQueueUtil.randInt(0, 99999); String key = "AES_KEY_TAKENUMB"; byte[] bytes = EncryptHelper.encrypt(key, String.format("%%%d%%%d", 1001, randomNumber)); String str = new String(bytes, "UTF8"); System.out.println("str = " + str); System.out.println(); byte[] utf8Bytes = str.getBytes("UTF8"); printBytes(utf8Bytes, "utf8Bytes"); } catch (Exception e) { e.printStackTrace(); }}public class EncryptHelper { public static byte[] encrypt(String key, String value) throws GeneralSecurityException { byte[] raw = key.getBytes(Charset.forName("UTF-8")); if (raw.length != 16) { throw new IllegalArgumentException("Invalid key size."); } SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec, new IvParameterSpec(new byte[16])); return cipher.doFinal(value.getBytes(Charset.forName("UTF-8"))); } public static String decrypt(String key, byte[] encrypted) throws GeneralSecurityException { byte[] raw = key.getBytes(Charset.forName("UTF-8")); if (raw.length != 16) { throw new IllegalArgumentException("Invalid key size."); } SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, skeySpec, new IvParameterSpec(new byte[16])); byte[] original = cipher.doFinal(encrypted); return new String(original, Charset.forName("UTF-8")); }}
答案1
小编典典当您按原样对字符串进行解码时UTF-8
,是因为您将字节编码为UTF-8或兼容格式。您不能只取一个byte[]
随机字节并将其转换为字符串,因为它是二进制数据而不是文本。
您可以做的是对二进制文件使用Base64编码器,并使用Base64解码器将其转换回原始字节。
这样做的一种怪癖方法是使用ISO-8859-1
,但这通常是个坏主意,因为您会混淆二进制数据和文本数据。
c# – Convert.ToBase64String / Convert.FromBase64String和Encoding.UTF8.GetBytes / Encoding.UTF8.GetString之间的区别
private byte[] key = Encoding.ASCII.GetBytes("abcdefgh"); private byte[] IV = Encoding.ASCII.GetBytes("hgfedcba"); private byte[] encrypted; public Form1() { InitializeComponent(); } private void btnEncrypt_Click(object sender,EventArgs e) { this.textBox2.Text = this.Encrypt(this.textBox1.Text); } private void btnDecrypt_Click(object sender,EventArgs e) { this.textBox3.Text = this.Decrypt(this.textBox2.Text); } private string Encrypt(string plainText) { try { using (DESCryptoServiceProvider crypto = new DESCryptoServiceProvider()) { crypto.Key = this.key; crypto.IV = this.IV; ICryptoTransform transform = crypto.CreateEncryptor(crypto.Key,crypto.IV); using (MemoryStream stream = new MemoryStream()) { using (CryptoStream cryptoStream = new CryptoStream(stream,transform,CryptoStreamMode.Write)) { using (StreamWriter writer = new StreamWriter(cryptoStream)) { writer.Write(plainText); } encrypted = stream.ToArray(); } } } return Convert.ToBase64String(encrypted); } catch (Exception) { throw; } } private string Decrypt(string cipherText) { try { string plainText = string.Empty; using (DESCryptoServiceProvider crypto = new DESCryptoServiceProvider()) { crypto.Key = this.key; crypto.IV = this.IV; ICryptoTransform transform = crypto.CreateDecryptor(crypto.Key,crypto.IV); using (MemoryStream stream = new MemoryStream(Convert.FromBase64String(cipherText))) { using (CryptoStream cryptoStream = new CryptoStream(stream,CryptoStreamMode.Read)) { using (StreamReader reader = new StreamReader(cryptoStream)) { plainText = reader.ReadToEnd(); } } } } return plainText; } catch (Exception) { throw; } }
一切都按预期工作.但如果我更换
return Convert.ToBase64String(encrypted);
和
using (MemoryStream stream = new MemoryStream(Convert.FromBase64String(cipherText)))
至
return Encoding.UTF8.GetString(encrypted);
和
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(cipherText)))
我在CryptoStream System.NotSupportedException中有错误.在诊断代码之后,我发现Encoding.UTF8.GetBytes(cipherText)具有比加密更多的字节
那么使用Convert.From / ToBase64String和Encoding.UTF8.GetBytes / GetString有什么区别呢?
解决方法
Base64是二进制到文本编码.它将字节编码为文本.
在这种情况下你需要后者.
Encoding.UTF8.GetString解码一个UTF-8编码的字节数组,如果存在无效的字节序列(这很有可能是像密文一样给它随机字节),那么它是有损的.
c# – Encoding.UTF8.GetString和Encoding.UTF8.GetBytes彼此不相反的原因是什么?
在以下示例中,myOriginalBytes和asBytes不相等,即使它们的长度不同.谁能解释我错过了什么?
byte[] myOriginalBytes = GetRandomByteArray(); var asstring = Encoding.UTF8.GetString(myOriginalBytes); var asBytes = Encoding.UTF8.GetBytes(asstring);
解决方法
让我们来看一个具体而简单的例子:单个字节0xff.这不是任何文本的有效UTF-8编码.所以如果你有:
byte[] bytes = { 0xff }; string text = Encoding.UTF8.GetString(bytes);
…你最终将文本作为单个字符,U+FFFD,“Unicode替换字符”,用于表示解码二进制数据时出错.对于任何无效序列,您最终会得到替换字符 – 例如,如果以0x80开头,则会获得相同的文本.显然,如果多个二进制输入被解码为相同的文本输出,则它不可能是完全可逆的变换.
如果您有任意二进制数据,则不应使用Encoding从中获取文本 – 您应该使用Convert.ToBase64String或者hex.编码用于自然文本的数据.
如果你走向相反的方向,像这样:
string text = GetRandomText(); byte[] bytes = Encoding.UTF8.GetBytes(text); string text2 = Encoding.UTF8.GetString(bytes);
…我希望text2等于文本,除了你有无效文本的奇怪情况,例如与“一半”代理对.
dede5.3生成列表假死问题的解决办法
打开include文件夹下arc.listview.class.php文件
在函数function __construct里添加 $this->CountRecord();
具体位置如下图
关于织梦 dede5.7,dedecms 5.7 utf8 首页分页,首页文档分页和织梦的首页怎么换图片的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于'str = new String(bytes,“ UTF8”)'和'bytes = str.getBytes(“ UTF8”)'中的字节数不相同、c# – Convert.ToBase64String / Convert.FromBase64String和Encoding.UTF8.GetBytes / Encoding.UTF8.GetString之间的区别、c# – Encoding.UTF8.GetString和Encoding.UTF8.GetBytes彼此不相反的原因是什么?、dede5.3生成列表假死问题的解决办法等相关知识的信息别忘了在本站进行查找喔。
本文标签: