|
|
|
@ -271,7 +271,7 @@ namespace Apewer |
|
|
|
/// <summary>转换字节数组为文本,默认使用 UTF-8 代码页。</summary>
|
|
|
|
public static string ToText(byte[] bytes, Encoding encoding = null) |
|
|
|
{ |
|
|
|
if (bytes.Length < 1) return Constant.EmptyString; |
|
|
|
if (bytes == null || bytes.Length < 1) return Constant.EmptyString; |
|
|
|
try { return (encoding ?? Encoding.UTF8).GetString(bytes); } |
|
|
|
catch { return Constant.EmptyString; } |
|
|
|
} |
|
|
|
@ -464,26 +464,23 @@ namespace Apewer |
|
|
|
{ |
|
|
|
if (files == null) return null; |
|
|
|
|
|
|
|
var output = new MemoryStream(); |
|
|
|
|
|
|
|
var input = null as Stream; |
|
|
|
using (var output = new MemoryStream()) |
|
|
|
{ |
|
|
|
var ex = ToZip(files.Keys, output, (name) => |
|
|
|
{ |
|
|
|
RuntimeUtility.Dispose(input); |
|
|
|
if (name.IsEmpty()) return null; |
|
|
|
|
|
|
|
var bytes = files[name]; |
|
|
|
if (bytes == null || bytes.LongLength < 1L) return null; |
|
|
|
|
|
|
|
input = new MemoryStream(); |
|
|
|
var input = new MemoryStream(); |
|
|
|
Write(input, bytes); |
|
|
|
input.Position = 0; |
|
|
|
return input; |
|
|
|
}, null, true); |
|
|
|
RuntimeUtility.Dispose(input); |
|
|
|
|
|
|
|
var result = output.ToArray(); |
|
|
|
RuntimeUtility.Dispose(result); |
|
|
|
return result; |
|
|
|
return output.ToArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>解压 ZIP 文件。</summary>
|
|
|
|
@ -997,7 +994,7 @@ namespace Apewer |
|
|
|
/// <exception cref="CryptographicException" />
|
|
|
|
public static byte[] AesDecrypt(byte[] cipher, byte[] key, CipherMode cipherMode = CipherMode.ECB, PaddingMode paddingMode = PaddingMode.PKCS7) |
|
|
|
{ |
|
|
|
return UseAes(cipher, key, null, cipherMode, paddingMode, (rijndael) => rijndael.CreateEncryptor(rijndael.Key, rijndael.IV)); |
|
|
|
return UseAes(cipher, key, null, cipherMode, paddingMode, (rijndael) => rijndael.CreateDecryptor(rijndael.Key, rijndael.IV)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>执行 AES 128/192/256 解密。</summary>
|
|
|
|
@ -1012,7 +1009,7 @@ namespace Apewer |
|
|
|
/// <exception cref="CryptographicException" />
|
|
|
|
public static byte[] AesDecrypt(byte[] cipher, byte[] key, byte[] iv, CipherMode cipherMode = CipherMode.ECB, PaddingMode paddingMode = PaddingMode.PKCS7) |
|
|
|
{ |
|
|
|
return UseAes(cipher, key, iv, cipherMode, paddingMode, (rijndael) => rijndael.CreateEncryptor(rijndael.Key, rijndael.IV)); |
|
|
|
return UseAes(cipher, key, iv, cipherMode, paddingMode, (rijndael) => rijndael.CreateDecryptor(rijndael.Key, rijndael.IV)); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|